library(dplyr)
## select col_1 as the first column, remove col_last, then create spanning
## structures that have multiple levels
##
## examples also assume the tfrmt has the column argument set to c(c1, c2, c3)
##
spanning_col_plan_ex <- col_plan(
col_1,
-col_last,
span_structure(
c1 = "Top Label Level 1",
c2 = "Second Label Level 1.1",
c3 = c(col_3, col_4)
),
span_structure(
c1 = "Top Label Level 1",
c2 = "Second Label Level 1.2",
c3 = starts_with("B")
),
span_structure(
c1 = "Top Label Level 1",
c3 = col_5
),
span_structure(
c2 = "Top Label Level 2",
c3 = c(col_6, col_7)
)
)
## select my_col_1 as the first column, then
## rename col_2 to new_col_1 and put as the
## second column, then select the rest of the columns
renaming_col_plan_ex <- col_plan(
my_col_1,
new_col_1 = col_2,
everything()
)
renaming_col_plan_ex2 <- col_plan(
my_col_1,
new_col_1 = col_2,
span_structure(
c1 = c(`My Favorite span name` = "Top Label Level 1"),
c3 = c(`the results column` = col_5)
)
)
## To one or more stub headers rename the corresponding group/label variables in the column plan.
## If multiple group variables exist, any of them can be renamed.
## Note: Multiple stub headers are only possible if the `row_grp_plan` label
## location is set to "column". Otherwise, if more than one group/label column is renamed,
## {tfrmt} will use the highest level group name available.
renaming_group <- col_plan(
my_grp = group, # rename group
label,
starts_with("col")
)
Run the code above in your browser using DataLab