我有一系列包含空字符串的值
levels(mydata$phone_partner_products) "" "dont_know" "maybe_interesting"
"not_interesting" "very_interesting" "very_not_interesting"
如果我制作频率表,我会得到这个 表(mydata$phone_partner_products)
dont_know maybe_interesting
3752 226 2907
not_interesting very_interesting very_not_interesting
1404 1653 1065
如何以更有意义的方式对列进行重新排序? 如何重命名空字符串“”级别?
提前非常感谢您。
最佳答案
使用levels()
重置您想要更改的因子级别:
> ff <- as.factor(sample(c("foo", "", "bar"),20,repl=TRUE))
> table(ff)
ff
bar foo
6 8 6
> levels(ff)
[1] "" "bar" "foo"
> levels(ff)[1] <- "ooops"
> table(ff)
ff
ooops bar foo
6 8 6
>
关于包含空字符串时的 R 表列顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3063243/