ff_relabel | R Documentation |
Variable labels can be created using ff_label
. Some functions
strip variable labels (variable attributes), e.g. forcats::fct_recode
.
Use this function to create a vector of variable labels from a data frame.
Then use ff_relabel
to relabel variables in data frame.
ff_relabel(.data, .labels) finalfit_relabel(.data, .labels)
.data |
Data frame to be relabelled |
.labels |
Vector of variable labels (usually created using
|
# Label variable colon_s$sex.factor %>% ff_label("Sex") %>% str() # Make factor level "Unknown" NA colon_s %>% dplyr::mutate_if(is.factor, forcats::fct_recode, NULL = "Unknown") %>% str() # Reset data data(colon_s) # Extract variable labels vlabels = colon_s %>% extract_variable_label() # Run function where labels are lost colon_s %>% dplyr::mutate_if(is.factor, forcats::fct_recode, NULL = "Unknown") %>% str() # Relabel colon_s %<>% ff_relabel(vlabels) colon_s %>% str()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.