【发布时间】:2014-06-05 10:42:42
【问题描述】:
我在计算标准偏差时遇到了一个意外 [至少对我来说] 错误。 想法 [*] 是将所有缺失值转换为 1,否则转换为 0。 然后在完成相关之前提取具有一些 [但不是全部] 缺失值的变量。使用 sd 函数尝试提取步骤,但失败 [为什么?]。
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 在行动中,罗伯特·卡巴科夫
【问题讨论】:
标签: r