Test of Missing Values
#Use is.na for testing for missing values
> y<-c(1,3,5,7,NA,11,NA,NA,17)
> is.na(y)
[1] FALSE FALSE FALSE FALSE TRUE FALSE TRUE TRUE FALSE
Recode Values to Missing Values
# recode 99 to missing for variable v1
# select rows where v1 is 99 and recode column v1
df$v1[df$v1==99] <- NA
Excluding Missing Values from Analyses
> x<-c(1,2,NA,3)
> mean(x) # returns NA
[1] NA
> mean(x,na.rm = TRUE) # returns 2
[1] 2
The function complete.cases() returns a logical vector indicating which cases are complete.