labelizor() substitutes text values shown in a flextable
with human-readable labels. This is useful to turn column
values such as variable names, factor levels or coded strings
into presentation-ready wording (e.g. "Sepal.Length" to
"Sepal Length").
labels can be either a named character vector (names
identify values to find, values are the replacement labels)
or a function applied to every text chunk (e.g. toupper()).
Only the displayed content is affected; the underlying data of the flextable is unchanged.
Arguments
- x
a 'flextable' object, see flextable-package to learn how to create 'flextable' object.
- j
column selector, see section Column selection with the
jparameter in <Selectors in flextable>.- labels
a named vector whose names will be used to identify values to replace and values will be used as labels.
- part
part selector, see section Part selection with the
partparameter in <Selectors in flextable>. Value 'all' can be used.
Examples
z <- summarizor(
x = CO2[-c(1, 4)],
by = "Treatment",
overall_label = "Overall"
)
ft_1 <- as_flextable(z, separate_with = "variable")
ft_1 <- labelizor(
x = ft_1, j = c("stat"),
labels = c(Missing = "Kouign amann")
)
ft_1 <- labelizor(
x = ft_1, j = c("variable"),
labels = toupper
)
ft_1
nonchilled
(N=40)
chilled
(N=42)
Overall
(N=82)
PLANT
Qn1
5 (12.5%)
0 (0.0%)
5 (6.1%)
Qn2
7 (17.5%)
0 (0.0%)
7 (8.5%)
Qn3
7 (17.5%)
0 (0.0%)
7 (8.5%)
Qc1
0 (0.0%)
7 (16.7%)
7 (8.5%)
Qc3
0 (0.0%)
7 (16.7%)
7 (8.5%)
Qc2
0 (0.0%)
7 (16.7%)
7 (8.5%)
Mn3
7 (17.5%)
0 (0.0%)
7 (8.5%)
Mn2
7 (17.5%)
0 (0.0%)
7 (8.5%)
Mn1
7 (17.5%)
0 (0.0%)
7 (8.5%)
Mc2
0 (0.0%)
7 (16.7%)
7 (8.5%)
Mc3
0 (0.0%)
7 (16.7%)
7 (8.5%)
Mc1
0 (0.0%)
7 (16.7%)
7 (8.5%)
TYPE
Quebec
19 (47.5%)
21 (50.0%)
40 (48.8%)
Mississippi
21 (52.5%)
21 (50.0%)
42 (51.2%)
CONC
Mean (SD)
445.6 (299.9)
435.0 (297.7)
440.2 (297.0)
Median (IQR)
350.0 (500.0)
350.0 (500.0)
350.0 (500.0)
Range
95.0 - 1,000.0
95.0 - 1,000.0
95.0 - 1,000.0
UPTAKE
Mean (SD)
30.8 (9.6)
23.8 (10.9)
27.2 (10.8)
Median (IQR)
31.3 (12.3)
19.7 (20.4)
28.3 (18.8)
Range
10.6 - 45.5
7.7 - 42.4
7.7 - 45.5
