0

I have some values such as -77777 which denote a special type of missing info in my dataset. I want to replace these with the smallest value or the largest value in their own column. Say I'm working with dataset HLDE and column is RTLM.

HLDE <- data.frame(RTLM = c(0:9, -77777))

This is not a duplicate! The so-called duplicate has no resemblance.

inekadam44
  • 11
  • 3
  • Not sure why you think it has no resemblance. You could probably use any of the solutions at the linked post on the vector `HLDE$RTLM`, as well as at the 2 posts *that* post links to. Have you tried those and found none of them to be similar to the answer you accepted here? If your question has more pitfalls, maybe they aren't covered by the example you posted. – camille Apr 25 '19 at 19:07

1 Answers1

1

Use conditional assignment with max or min. To make it more robust set na.rm=TRUE.

HLDE[HLDE$RTLM == -77777, "RTLM"] <- max(HLDE$RTLM, na.rm=TRUE)
jay.sf
  • 60,139
  • 8
  • 53
  • 110