Search code examples
rnarecode

recoding integers in a vector so they register as NA instead?


I hope this isn't a silly question but I am REALLY struggling to recode a variable in R so that certain values register as NA instead of the placeholder integer that got read in. respondents who did not answer the question for that column were originally coded as -88, -89 and -99 instead of NA and I only know how to remove them completely from that column.

I want to keep that row, just have those inputs registered as missing. Recode doesn't seem to work b/c NA isn't a value

Thanks!


Solution

  • Maybe you can try replace

    v <- replace(v,v%in%c(-88,-89,-99),NA)
    

    such that

    > v
    [1]  1  2 NA NA -1 NA NA
    

    Dummy Data

    v <- c(1,2,-88,-89,-1,-99,-89)