recover_labs | R Documentation |
Many operations, such as rbind, cbind or its tidyverse analogues, strips
out the variable labels. Use recover_labs()
to bring them back from a
tibble
or data.frame
where they are last present. The function attempts a
few checks for new and original data compatibility. Note that the infix
operator is available for a quick and self-explanatory usage.
recover_labs(new_data, orig_data)
new_data %labs_from% orig_data
new_data |
new dataframe that you want to recover the labs for |
orig_data |
original dataframe with variable labels present |
Tibble or data.frame with variable labels restored.
# make labels for iris dataset, labels will be colnames
# with dot replaced for whitespace
iris_with_labs <- as.data.frame(mapply(function(x, y) {
attr(x, "label") <- y
return(x)
}, iris, gsub("\\.", " ", colnames(iris)), SIMPLIFY = FALSE))
iris_with_recovered_labs <- recover_labs(iris, iris_with_labs)
iris_with_recovered_labs_infix <- iris %labs_from% iris_with_labs
# check
get_labs_df(iris_with_recovered_labs)
get_labs_df(iris_with_recovered_labs_infix)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.