draw
draw

Reputation: 4846

How to get the description of column name in tibble?

In R, I am using qualtRics package to read my Qualitrics data using which uses sjlabelled to set labels.

How do I get "What would you.." in the following image?

Here is the output for 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?" 

Edit: I tried attr function:

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

Upvotes: 0

Views: 919

Answers (1)

r2evans
r2evans

Reputation: 160667

To get the attribute itself, use

attr(raw$QA1, "label")

This will get you a named character vector, and while you can use that just fine in anything that expects a string, if you prefer to remove the name (for console aesthetics), then you can use the unname function as well:

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

Upvotes: 2

Related Questions