Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new function suggestion: get_var_labels #297

Closed
HanjoStudy opened this issue Jul 6, 2017 · 2 comments
Closed

new function suggestion: get_var_labels #297

HanjoStudy opened this issue Jul 6, 2017 · 2 comments

Comments

@HanjoStudy
Copy link

HanjoStudy commented Jul 6, 2017

I find a constantly need to extract and work with the labels of a .sav file after I have read in the file using read_sav. The difficulty is extracting and relabeling the label attribute.

Currently I use the following function from this thread:

get_var_labels = function(data) {
  a = do.call(Hmisc::llist, data)
  tempout = vector("list", length(a))

  for (i in 1:length(a)) {
    tempout[[i]] = Hmisc::label(a[[i]])
  }
  b = unlist(tempout)
  structure(c(b), .Names = names(data))
}

It would be handy if this function formed part of the haven package without having to be dependent on Hmisc

@larmarange
Copy link
Contributor

If needed, the labelled package (https://cran.r-project.org/package=labelled) provides dedicated functions to manipulate labelled vectors.

@HanjoStudy
Copy link
Author

Thanks, this is the type of functionality that I was looking for!

@lock lock bot locked and limited conversation to collaborators Jun 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants