I have an unexpected [for me at least] error in calculating a standard deviation. The idea [*] is to convert all missing values to 1 and 0 otherwise. Then extract variables that have some [but not all] missing values, before a correlation is done. That extraction step is attempted with a sd function, but it fails [why?].
library(VIM)
data(sleep) # dataset with missing values
x = as.data.frame(abs(is.na(sleep))) # converts all NA to 1, otherwise 0
y = x[which(sd(x) > 0)] # attempt to extract variables with missing values
Error in is.data.frame(x) :
(list) object cannot be coerced to type 'double'
# convert to double
z = as.data.frame(apply(x, 2, as.numeric))
y = z[which(sd(z) > 0)]
Error in is.data.frame(x) :
(list) object cannot be coerced to type 'double'
[*] R in Action, Robert Kabacoff