如果在我的调查数据中(从csv文件加载)我有一个带有5个响应选项的变量,但是Ps只响应1:4,是否有任何R函数将输出“5”如果我将该函数应用于变量?
答案 0 :(得分:0)
您需要将该列重新指定为具有 变量所需的适当级别的因子。
#Assuming that the values in myDF$myVar have the values 1:4, but COULD have been 1:5.
myDF$myVar <- factor(
x=myDF$myVar,
levels=1:5,
labels=c('What a 1 means', 'What a 2 means',
'What a 3 means', 'What a 4 means',
'What a 5 means')
)