0

I'm currently working on an updated version of a dataset that I have worked on previously in R-Studio. The new update features coding for missing values rather than leaving these cells blank.

The issue with this coding is that they are numeric values which interfere with my analysis and modelling specifically looking at values of age (also numeric in this column), skewing my models.

I am looking for a way to replace values that are specifically coded as missing (e.g. the code for a missing value is 9998) with N/A within the dataframe of R-Studio.

joran
  • 169,992
  • 32
  • 429
  • 468

1 Answers1

0

Something like this, perhaps?

d <- data.frame(x = 1:5,y = letters[1:5],z = c(NA,1:4))
> d$x[3] <- 9998
> d
     x y  z
1    1 a NA
2    2 b  1
3 9998 c  2
4    4 d  3
5    5 e  4
> d[d == 9998] <- NA
> d
   x y  z
1  1 a NA
2  2 b  1
3 NA c  2
4  4 d  3
5  5 e  4
joran
  • 169,992
  • 32
  • 429
  • 468