我有一个数据框中的变量,其中包含以下语句:“应要求移民适应德国的习俗”。变量的类别是非常同意、同意、都不是、不同意、非常不同意。这是变量的频率表:
> count(dat, 'c2a')
c2a freq
1 agree 201
2 disagree 214
3 neither 156
4 no answer 15
5 strongly agree 65
6 strongly disagree 138
我想将变量从文本重新编码为数字。我这样做:
library(dplyr)
dat$c2a <- recode(dat$c2a, 'strongly disagree' = 1, 'disagree' = 2,
'neither' = 3, 'agree' = 4, 'strongly agree' = 5)
但是后来我从 R 收到以下警告消息:警告消息:未替换的值被视为 NA 作为 .x 不兼容。请详尽地指定替代品或提供 .default
我如何指定所有不同于 1 或 2 或 3 或 4 或 5 的 c2a 值都是 NA?
这些值已经NA
使其明确并使警告消失.default
在recode
.
dplyr::recode(dat$c2a,'strongly disagree' = 1, 'disagree' = 2, 'neither' = 3,
'agree' = 4, 'strongly agree' = 5, .default = NA_real_)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句