df <- data.frame(replicate(10,sample(0:100,1000,rep=TRUE)))
eee <- as.data.frame(lapply(df, function(cc) cc[ sample(c(TRUE, NA), prob = c(0.85, 0.15), size = length(cc), replace = TRUE) ]))
View(eee)
This gives me a data frame with missing data.
If a variable in my current data frame has missing values, then I want to create two new variables. The first being a binary "yes" this was missing or "no" it wasn't missing. I want the second variable to be the same as the original, if the variable is not missing. If it is missing, I want to impute the mean of the original variable for my new column.
I'm not sure how to write the code to do this checking my whole data set instead of doing each variable individually.
Thank you for the help!