Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


unheadr (version 0.4.0)

untangle2: Rectangling embedded subheaders

Description

Rectangling embedded subheaders

Usage

untangle2(df, regex, orig, new)

Value

A tibble without the matched subheaders and a new variable containing the grouping data.

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.

Examples

Run this code
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
  )

Run the code above in your browser using DataLab