【发布时间】:2019-07-02 17:32:35
【问题描述】:
我想使用嵌入在其他向量中的describe() 传递向量,以便我可以在for 循环中使用该函数。
我有以下数据,其中包含一组学生的成绩。
我想获得 130 名学生分入的 5 个不同组的描述性统计数据,因此我为每个组创建了一个子集。
pr3 <- read.csv("data.csv", head = T, sep = ";")
G1A <- subset(pr3, group == "1A")
G1B<- subset(pr3, group == "1B")
现在调用describe() 如下完美:
describe(G1A)
但是,将子集分组到向量 names 并将索引 names 传递给 describe() 将不起作用:
names <- c(G1A, G1B)
describe(names[1])
Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
is.atomic(x) is not TRUE
In addition: Warning message:
In mean.default(x, na.rm = na.rm) :
argument is not numeric or logical: returning NA
>
我怎样才能让它工作?
【问题讨论】: