I use R to generate examples of how to handle the missing data for the statistics class that I teach. One method requires the generation of "missing binary variable values", with 0 for cases containing missing values, and 1 without missing values. for example
n XYZ 1 4 300 2 2 8 400 4 3 10 500 7 4 18 NA 10 5 20 50 NA 6 NA 1000 5
I would like to generate a variable M such that
nm 1 1 2 1 3 1 4 0 5 0 6 0
This seems to be simple given the ability of R to handle missing values. The closest I found is m <-ifelse(is.na(missguns),0,1) , but all this creates a new whole data matrix with 0 or 1, indicating absence. However, I just need one variable indicating whether the string contains the missing values.
r missing-data dummy-data
jeramy townsley
source share