Likert中的错误:R中所有项目(列)必须具有相同的级别数

Gra*_* Li 6 r likert

我的数据:

        Q5         Q6          Q7
1   Not Agree   Neutral     Not Agree
2   Not Agree   Neutral     Neutral
3   Not Agree   Agree       Agree
4   Not Agree   Agree       Neutral
5   Neutral     Not Agree   Neutral
6   Not Agree   Agree       Neutral
7   Not Agree   Neutral     Neutral
8   Neutral     Agree       Neutral
9   Agree       Neutral     Not Agree
10  Neutral     Agree       Neutral
Run Code Online (Sandbox Code Playgroud)
Q567[1:3] <- lapply(Q567[1:3], factor, levels= c("Agree", "Neutral", "Not Agree"), ordered = TRUE)

likert(Q567) %>%
  plot(type = "bar")
Run Code Online (Sandbox Code Playgroud)

我的数据是什么样的
我的数据是什么样的

我将它们转换为带有级别的因子,为什么我仍然收到错误

Error in likert(Q567) : All items (columns) must have the same number of levels
Run Code Online (Sandbox Code Playgroud)

小智 16

我遇到了同样的问题,发现我正在使用的集合是 tibble,而不是 data.frame:

data <- as.data.frame(data) 
Run Code Online (Sandbox Code Playgroud)

为我修好了。


LMc*_*LMc 0

您仅将数据帧的前三列重新编码为因子,但将整个数据帧传递给likert. 该likert函数期望 中的变量Q567是因子。所以我相信您的数据框中还有其他列,这导致了您的错误。

你应该做类似的事情:

likert(Q567[,1:3]) %>% 
  plot(type = 'bar')
Run Code Online (Sandbox Code Playgroud)