处理R中李克特量表的缺失值



我的数据在一个称为 studentData的变量中具有5列。每列有326行,除了缺少3行的一行。每列都是5点李克特值,从集合mylevels <- c('Strongly disagree', 'Disagree', 'Neither agree nor disagree', 'Agree', 'Strongly agree')

当我打印每一列中的级别数量时,它为我的第二列的值(StudentData $增加。信心(,因为它具有3个缺失值,这些值将其解释为此列的另一个因素。

> sapply(studentData, function(x) { length(levels(x)) } ) # The number of levels in each factor
              ï..Increased.engagement                  Increased.confidence               Improved.writing.skills 
                                    5                                     6                                     5 
   Made.useful.contribution.to.course Should.keep.games.for.future.students 
                                    5                                     5 

因此,我发现错误,指出李克特函数的工作量应该相同。我应该如何处理这3个丢失值?

> studentLikert <- likert(studentData)
Error in likert(studentData) : 
  All items (columns) must have the same number of levels

尝试以下操作:将列定义为因子,以确保通过使用ubl dubl ='''

将丢失值排除在因子级别定义中
a <- c('A','B','C','','A')
b <- c('A','B','A','C','B')
df <- data.frame(a,b)
mylevels <- c('A', 'B', 'C')
df <- as.data.frame(lapply(df,function(x) {factor(x,levels=mylevels, exclude="")}))

最新更新