r - 在 R 中,我如何在属性中设置命名向量的名称
问题描述
我正在使用 SPSS 将数据读入haven
R。其中一个变量的labels
属性非常长:
> attributes(source$VAX8_behavior)
$label
[1] "Which of the following applies to you regarding the COVID-19 vaccine? [8M]"
$format.spss
[1] "F3.0"
$display_width
[1] 7
$class
[1] "haven_labelled" "vctrs_vctr" "double"
$labels
Decline to answer
-999
Item not shown
-888
Data entry error
-777
Failed attention check
-666
Lost to follow-up
-555
Cannot Calculate
-444
I am not planning to get the COVID-19 vaccine
1
I am considering getting the COVID-19 vaccine
2
I am actively planning to get the COVID-19 vaccine (e.g., I have scheduled an appointment to get the vaccine or plan to
3
所以,我想改变这个:
attr(source$VAX8_behavior, "labels")[9]
I am actively planning to get the COVID-19 vaccine (e.g., I have scheduled an appointment to get the vaccine or plan to
如何将其更改为“......我已经安排了约会......”?也就是说,在作为属性的命名向量上更改名称的语法是什么?
这不起作用:
attr(source$VAX8_behavior, "labels")[9] <-
"... I have scheduled an appointment ..."
因为它设置的值不是标签:
$labels
Decline to answer
"-999"
Item not shown
"-888"
Data entry error
"-777"
Failed attention check
"-666"
Lost to follow-up
"-555"
Cannot Calculate
"-444"
I am not planning to get the COVID-19 vaccine
"1"
I am considering getting the COVID-19 vaccine
"2"
I am actively planning to get the COVID-19 vaccine (e.g., I have scheduled an appointment to get the vaccine or plan to
"... I have scheduled an appointment ..."
我猜测解决方案需要setNames()
或mostattributes()
.
抱歉,我无法提供 ReprEx,因为我没有 SPSS,而且数据是机密的。
解决方案
推荐阅读
- c - Win32:从 DLG 文件创建选项卡控件。这怎么可能?
- c++ - 来自转储的访问冲突异常。有什么方法可以查看它发生的变量是什么?
- java - 如何在扩展类类型的arrayList中查找单词的频率
- javascript - 或 正则表达式中的条件
- python - 如何使用 xlsxwriter(不带熊猫)将一组列表写入 Excel?
- python - 根据 .CSV 文件中的列数据识别列名
- excel - 如何在 MS Excel 中为一行创建动态范围?
- asp.net-mvc - 如何使用状态码重定向到 MVC 控制器中的另一个 URL
- google-people-api - People API 上的持久化操作似乎比 Contacts API 上的慢得多
- isabelle - Sledgehammer 如何将 lambda 抽象转换为 ATP?