0

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 (a.k.a 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!

asked Apr 7, 2020 at 2:00
1
  • cold you add a dput of your data? Commented Apr 7, 2020 at 5:25

2 Answers 2

1

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") )
answered Apr 7, 2020 at 5:28
Sign up to request clarification or add additional context in comments.

Comments

1

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".

answered Apr 24, 2020 at 14:41

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.