ff_relabel: Relabel variables in a data frame

Description Usage Arguments Examples

View source: R/ff_label.R

Description

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.

Usage

1
2
3
ff_relabel(.data, .labels)

finalfit_relabel(.data, .labels)

Arguments

.data

Data frame to be relabelled

.labels

Vector of variable labels (usually created using extract_variable_label).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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()
  

finalfit documentation built on June 11, 2021, 5:17 p.m.