Hadley Wickham\'s haven
package, applied to a Stata file, returns a tibble with many columns of type \"labeled\". You can see these with str(), e.g.:
The original question asks how 'to extract the values of the labels attribute to a list.' A solution to the main question follows (assuming some_df
is imported via haven
and has label
attributes):
library(purrr)
n <- ncol(some_df)
labels_list <- map(1:n, function(x) attr(some_df[[x]], "label") )
# if a vector of character strings is preferable
labels_vector <- map_chr(1:n, function(x) attr(some_df[[x]], "label") )