unbreak_vals {unheadr} | R Documentation |
Unbreak values using regex to match the lagging half of the broken value
Description
Unbreak values using regex to match the lagging half of the broken value
Usage
unbreak_vals(df, regex, ogcol, newcol, sep = " ", slice_groups)
Arguments
df |
A data frame with one or more values within a variable broken up across two rows. |
regex |
Regular expression for matching the trailing (lagging) half of the broken values. |
ogcol |
Variable to unbreak. |
newcol |
Name of the new variable with the unified values. |
sep |
Character string to separate the unified values (default is space). |
slice_groups |
Deprecated. See details and Package News. |
Details
This function is limited to quite specific cases, but useful when
dealing with tables that contain, for example, scientific names broken across two rows.
For unwrapping values, see unwrap_cols
.
Value
A tibble with 'unbroken' values. The variable that originally
contained the broken values gets dropped, and the new variable with the
unified values is placed as the first column. The slice_groups
argument is now deprecated; the extra rows and the variable with broken
values will be dropped.
Examples
data(primates2017_broken)
# regex matches strings starting in lowercase (broken species epithets)
unbreak_vals(primates2017_broken, "^[a-z]", scientific_name, sciname_new)