【问题标题】:Psych function describe() with Embedded Vector Returns Error in Var带有嵌入式向量的 Psych 函数 describe() 在 Var 中返回错误
【发布时间】: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
>

我怎样才能让它工作?

【问题讨论】:

    标签: r for-loop psych describe


    【解决方案1】:

    您不能将您的子集/数据帧放在一个向量中并以这种方式调用它们。

    如果您致电str(names[1]) 来查看您的向量的结构,您就会明白为什么它不起作用。

    相反,您可能希望将两个数据框放在一个列表中,以便用您的第二行调用它们。像这样:

    names <- list(G1A, G1B)
    describe(names[1])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      • 2012-10-29
      • 1970-01-01
      • 2014-08-05
      • 1970-01-01
      相关资源
      最近更新 更多