简体   繁体   中英

R extract labels from a rda data frame

I am looking at some data downloaded from ICPSR and I am specifically using their R data file (.rda). Beneath the column name of each data file, there are some descriptions of the variables (aka labels). An example is attached as well.

I tried various ways to get the label including base::label, Hmisc::label, labelled::var_label, sjlabelled::get_label and etc. But none worked.

So I am asking any ideas on how to extract the labels from this data file?

Thanks very much in advance!

this could work using purrr

#load library
library(purrr)

#get col n
n <- ncol(yourdata)

#extract labels as vector
labels <- map_chr(1:n, function(x) attr(yourdata[[x]], "label") )

This worked for me (I am working with ICPSR 35206):

attributes(yourdata)$variable.labels -> labels

Make sure that your attribute referring to the labels is actually called "variable.labels".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM