问题描述
我正在使用 R 并且有一个包含约 3000 个心理测试数据的数据集。大部分数据存储为字符串变量:
> table(rona_full$FQ169_6)
At no time Some of the time Less than half the time More than half the time
418 73 48 36
Most of the time All of the time
20 9
我想将字符串数据重新编码为变量:
> table(rona_full$FQ169_6)
0 1 2 3 4 5
443 63 39 30 21 9
目前,这是我的方法:
rona_full$FQ169_6 <-ifelse(rona_full$MQ169_6 == "At no time",#this recodes MDI from string
ifelse(rona_full$MQ169_6 == "Some of the time",1,ifelse(rona_full$MQ169_6 == "Less than half the time",2,ifelse(rona_full$MQ169_6 == "More than half the time",3,ifelse(rona_full$MQ169_6 == "Most of the time",4,5)))))
我想有一种更有效的方法可以在 25 多列上执行完全相同的重新编码,而不是以这种方式进行每一列。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)