问题描述
我继承了过去在 SPSS 中处理的大量(约 200 个变量)数据集,其中每个变量最多可以有 50 多个“编码”级别,未标记。见下文:
df$CountryOfBirth
[1] 1201 1201 2010 9124 1101 4105 1101
在这种情况下,每个数字对应一个国家(例如,1201 = 英国;1101 = 法国)。鉴于对于一个“代码”我有一个“标签”,在这种情况下进行替换很容易。
问题是,在这个数据集中,我还有其他“类似问卷”的变量,有时共享相同的级别,有时不共享。此外,这些问题有多次重复,对应于基本上在一年中的不同时间问过的同一个问题(TiredQuestion1;TiredQuestion2;TiredQuestion3...)
df$TiredQuestion1
[1] 1 2 2 3 1 2 1 1 1 1 3 2 1 4
Labels:
value label
1 None of the time
2 A little of the time
3 Some of the time
4 Most of the time
5 All of the time
df$LivingQuestion1
[1] 4 2 5 4 5 5 5 4
Labels:
value label
1 Very satisfied
2 dissatisfied
3 neither satisfied nor dissatisfied
4 satisfied
5 very good
正如您在上面看到的,使用 haven()
、sjlabelled()
之类的包,我设法从 SPSS 中提取了数据框,包括每个变量的值和标签。
鉴于此数据集几乎每周都会更新新条目,我正在尝试获取每个变量的值和标签,将它们存储起来并在数据集更新时将它们匹配到“新”变量上(见下文) .
df$TiredQuestion1
[1] "None of the time" "A little of the time" "A little of the time" "Some of the time"
Labels:
value label
1 None of the time
2 A little of the time
3 Some of the time
4 Most of the time
5 All of the time
df$CountryOfBirth
[1] "England" "France" "Spain" "Bosnia"
Labels:
value label
1101 England
2010 France
3010 Spain
5010 Bosnia
...
我曾尝试使用 codebook()
、memisc()
和 asciiSetupReader()
,但都没有成功。
如果我能听到您对此的看法,我会非常高兴,因为我开始认为我处理这个问题的方式是错误的。
提前致谢, 朱利安
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)