0

我有一个 10 点李克特量表,如下所示:

    > head(dsidata$Mood_2)
[1] Great Great Bad   Good  Great So-so
Levels: Couldn't be worse Very bad Bad Meh So-so Okay Good Very Good Great Really great

我想“合并”类别,使因素数量减少到 5 个。选择“不可能更糟”或“非常糟糕”选项的受访者将被分配新类别“非常负面”等,直到 10 个因素减少到5。

非常感谢任何帮助

4

2 回答 2

2

我确定您的变量被归类为一个因素。因此,只需使用这种方法合并一些因素。

set.seed(42)  # for reproducibility

# mimicking your data
df1 <- data.frame(var=rdunif(100, 10))
df1$var <- factor(df1$var, 1:10, labels=c("Couldn't be worse", "Very bad", 
                                        "Bad", "Meh", "So-so", "Okay",
                                        "Good", "Very Good", "Great", 
                                        "Really great"))

df1$var1 <- df1$var

# merging levels
levels(df1$var1) <- list("Very negative"=c("Couldn't be worse", "Very bad"),
                        "negative" = c("Bad", "Meh"),
                        "neutral" = c("So-so", "Okay"),
                        "positive"=c("Good", "Very Good"),
                        "very positive"=c("Great", "Really great"))

屈服

> tail(df1, 10)
                  var          var1
91           Very bad Very negative
92          Very Good      positive
93           Very bad Very negative
94           Very bad Very negative
95  Couldn't be worse Very negative
96  Couldn't be worse Very negative
97               Okay       neutral
98           Very bad Very negative
99          Very Good      positive
100         Very Good      positive
于 2018-05-24T12:28:16.833 回答
1

这取决于您的数据集,但您可以这样做:

dsidata$Mood_2_newscale <- ifelse(dsidata$Mood_2 %in% c("Couldn't be worse","Very bad"),
"Very negative",
dsidata$Mood_2)
于 2018-05-24T11:53:41.697 回答