2017-10-09 113 views
1

我正在嘗試使用RStdudio v1.0.153生成一個帶有likert刻度數據的R圖。我收到以下錯誤:R(likert)包的問題

Error in likert(think) : 
All items (columns) must have the same number of levels 

鏈接到我的數據是:https://docs.google.com/spreadsheets/d/1TYUr-_oX9eADZ6it1w_4CQJ_wITP6xISaJJHTad3JbA/edit?usp=sharing

下面是R碼我用:

> library(psych) 
> library(likert) 

> myColor <- c("red","orange", "light blue","light green", "lavender") 
> levels = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree") 

> think$A = factor(think$A, levels, ordered = TRUE) 
> think$B = factor(think$B, levels, ordered = TRUE) 
> think$C = factor(think$C, levels, ordered = TRUE) 
> think$D = factor(think$D, levels, ordered = TRUE) 
> think$E = factor(think$E, levels, ordered = TRUE) 
> think$F = factor(think$F, levels, ordered = TRUE) 

> results <- likert(think) 
> plot(results, col = myColor) #Have not used this yet because of the error above 
+0

這是很難幫助你當數據位於一些外部網站。請參閱[如何創建一個可重現的示例](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example),讓您的問題自給自足。如果我們無法複製/粘貼代碼來運行和測試代碼,那麼幫助您會花費更多時間。 – MrFlick

回答

0

likert命令需要輸入的數據幀。
您應該使用likert(as.data.frame(think))

library(psych) 
library(likert) 
library(readxl) 
think <- read_xlsx(path="ThinkData.xlsx") 

myColor <- c("red","orange", "light blue","light green", "lavender") 
levels = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree") 

think$A = factor(think$A, levels, ordered = TRUE) 
think$B = factor(think$B, levels, ordered = TRUE) 
think$C = factor(think$C, levels, ordered = TRUE) 
think$D = factor(think$D, levels, ordered = TRUE) 
think$E = factor(think$E, levels, ordered = TRUE) 
think$F = factor(think$F, levels, ordered = TRUE) 

results <- likert(as.data.frame(think)) 
plot(results, col = myColor) 

enter image description here