unwrap_cols: Unwrap values and clean up NAs used as padding

View source: R/unwrap_fn.R

unwrap_colsR Documentation

Unwrap values and clean up NAs used as padding

Description

Unwrap values and clean up NAs used as padding

Usage

unwrap_cols(df, groupingVar, separator)

Arguments

df

A data frame with wrapped values and an inconsistent number of NA values used to as within-group padding.

groupingVar

Name of the variable describing the observational units.

separator

Character string defining the separator that will delimit the elements of the unwrapped value.

Details

This is roughly the opposite of tidyr::separate_rows().

Value

A summarized tibble. Order is preserved in the grouping variable by making it a factor.

Examples

data(primates2017_wrapped)
# using commas to separate elements
unwrap_cols(primates2017_wrapped, scientific_name, ", ")

# separating with semicolons
df <- data.frame(
  ounits = c("A", NA, "B", "C", "D", NA),
  vals = c(1, 2, 2, 3, 1, 3)
)
unwrap_cols(df, ounits, ";")

luisDVA/unheadr documentation built on Aug. 16, 2022, 5:28 a.m.