如何获取标题中列名称的描述?

时间:2019-07-22 21:30:48

标签: r rstudio

在R中,我使用qualtRics包读取我的Qualitrics数据,并使用sjlabelled设置标签。

如何在下图中显示“您会怎样?”?

以下是print的输出:

> print(raw$QA1)
[1] "Red and black" "Red and black" "Red and black" "Red and black"
[5] "Red and black" "Red and black" NA              NA             
[9] NA             
attr(,"label")
                             QA1 
"What's the color of the robot?" 

编辑:我尝试了attr函数:

> print(attr(raw$QA1, "label"))
                             QA1 
"What's the color of the robot?" 

1 个答案:

答案 0 :(得分:1)

要获取属性本身,请使用

attr(raw$QA1, "label")

这将为您提供一个名为 character的向量,并且您可以在需要字符串的任何内容中使用该向量,但是如果您希望删除该名称(出于控制台美观的考虑) ,那么您也可以使用unname函数:

unname(attr(raw$QA1, "label"))