collapse_to_distinct_rows: Collapse ID cols to distinct rows

View source: R/utils.R

collapse_to_distinct_rowsR Documentation

Collapse ID cols to distinct rows

Description

Imagine you have a dataframe with two id columns that contain two rows that actually are just one combination. This function distincts them within a purrr workflow, see example.

Usage

collapse_to_distinct_rows(...)

Arguments

...

string or numeric vectors, typically id columns

See Also

Copied from https://stackoverflow.com/a/62381665/2646974

Examples

## Not run: 
df <- data.frame(id_1 = c(1,2), id_2 = c(2,1))
df %>%
  dplyr::mutate(id_1_id_2 = purrr::map2_chr(id_1, id_2, collapse_to_distinct_rows)) %>%
  dplyr::distinct(id_1_id_2, .keep_all = TRUE) %>%
  dplyr::select(-id_1_id_2)
  
## End(Not run)

cutterkom/kabrutils documentation built on July 3, 2022, 4:04 p.m.