untangle2 {unheadr} | R Documentation |
Rectangling embedded subheaders
Description
Rectangling embedded subheaders
Usage
untangle2(df, regex, orig, new)
Arguments
df |
A data frame with embedded subheaders. |
regex |
Regular expression to match the subheaders. |
orig |
Variable containing the extraneous subheaders. |
new |
Name of variable that will contain the group values. |
Details
Special thanks to Jenny Bryan for fixing the initial tidyeval code and overall function structure.
Value
A tibble without the matched subheaders and a new variable containing the grouping data.
Examples
data(primates2017)
# put taxonomic family in its own variable (matches the suffix "DAE")
untangle2(primates2017, "DAE$", scientific_name, family)
# put geographic regions in their own variable (matching them all by name)
untangle2(
primates2017, "Asia|Madagascar|Mainland Africa|Neotropics",
scientific_name, family
)
# with magrittr pipes (re-exported in this package)
primates2017 %>%
untangle2("DAE$", scientific_name, family) %>%
untangle2(
"Asia|Madagascar|Mainland Africa|Neotropics",
scientific_name, region
)
[Package unheadr version 0.4.0 Index]