>attach(dataset)
> summary(variable)
>table(variable)
>table(as.numeric(variable))
>levels(variable) ##if that s a numeric factor, it will have error message. command above just to have idea of how many NA and what value of level to recode.
>levels(variable) [level value assigned] <- NA
#to check
>sum(is.na(variable))
# it tells you how many are missing, or
>table(as.numeric(variable))
#or
> levels(variable)
## NA level should appear then.
missing value for numeric variables:
> sum(is.na(BYSES2))
[1] 0
> BYSES2[BYSES2==-8] <- NA
> sum(is.na(BYSES2))
[1] 305
> BYSES2[BYSES2==-4] <- NA
> sum(is.na(BYSES2))
[1] 953
> describe(BYSES2)
Note: if type:
> variable[1:4] <- NA ## it means assign NA to the 1st to 4th row under this column(variable)
> variable[3] <- NA ## Likewise, assign NA to the 3rd row under the variable
It is little bit confusing but finally made it!
This is exactly what I was looking for, but is there a way to recode for multiple variables at once?
ReplyDelete