有没有办法获取R中列的所有标签属性

Is there a way to get all the label attributes of columns in R

我使用 qualtRics 包中的 read_survey() 命令创建了一个数据框。数据框的变量(列)有一个名称(例如“Q1”),但它们也有一个标签属性(例如“你的年龄是多少?”)。有没有一种方法可以访问所有标签并将它们放在一个很好的概述中,例如列表或单独的数据框?

我已经能够使用以下方法单独访问每个标签:

attributes(df$Q1)

结果如下:

$label
                                                         Q1 
" What is your age?"

我知道我应该提供一个可重现的数据框来澄清我的问题,但是我不知道如何创建这些标签属性。

我想要的结果数据框看起来像这样:

Column 1           Column 2
Q1                 "What is your age?"
Q2                 "What is your name?"
etc                etc (i.e.The rest of the labels)

或者用包含所有标签的列表代替数据框。

这是否回答了您的问题?

Q1 = runif(5)
Q2 = runif(5)

attributes(Q1)$label <- c("What is your age?")
attributes(Q2)$label <- c("What is your name?")


df <- data.frame(Q1, Q2)

purrr::map_df(df, ~attributes(.x)) %>%
  bind_cols(names = names(df), .)