group_by_coalesce: A all in one group by and coalesce function

View source: R/group_by_coalesce.R

group_by_coalesceR Documentation

A all in one group by and coalesce function

Description

Groups by and coalesces the remaining columns such that only one value is returned per column. If multiple values are present that are not NA a warning is returned with the offending group, column name, and values.

Usage

group_by_coalesce(.data, ..., .ignore = c(), .method = "first", debug = FALSE)

Arguments

.data

A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr).

...

one or more unquoted expressions separated by commas. Variable names can be used as if they were positions in the data frame, so expressions like x:y can be used to select a range of variable

.ignore

which columns to ignore for warnings

.method

either 'first' or 'sum'

debug

logical, print debug statements

Value

vector of coalesced values

Examples

df_safe <- data.frame(
    A=c(1,1,2,2,2),
    B=c(NA,2,NA,NA,4),
    C=c(3,NA,NA,5,NA),
    D=c(NA,2,3,NA,NA),
    E=c(NA,NA,NA,4,NA))

df_warn <- data.frame(
    A=c(1,1,2,2,2),
    B=c(NA,2,NA,4,4),
    C=c(3,NA,NA,5,NA),
    D=c(NA,2,3,NA,NA),
    E=c(NA,NA,NA,4,5))

group_by_coalesce(df_safe, A)
group_by_coalesce(df_warn, A)


uclalawcovid19behindbars/behindbarstools documentation built on April 22, 2022, 4:08 a.m.