e_coalesce_by_column: Combine rows with different data values

View source: R/e_complete_multiple_keys_ALL.R

e_coalesce_by_columnR Documentation

Combine rows with different data values

Description

For matching group_by() keys, keeps first non-NA value for each column.

Usage

e_coalesce_by_column(dat)

Arguments

dat

data.frame of keys (or other columns) to combine

Value

coalesced data.frame

Examples

dat <-
  # A = 1, easy
  # A = 2, easy
  # A = 3, 3rd row has a dup and NA
  # A = 4, 3rd row has conflucing info
  tibble::tribble(
   ~A, ~B, ~C, ~D, ~E
  , 1, NA,  3, NA,  5
  , 1,  2, NA,  2, NA
  , 2, NA, NA,  3, NA
  , 2,  4,  5, NA,  4
  , 3, NA, NA,  3, NA
  , 3,  4,  5, NA,  4
  , 3,  4, NA, NA,  4
  , 4, NA, NA,  3, NA
  , 4,  4,  5, NA,  4
  , 4, 99, 99, 99, NA
  )

dat |>
  dplyr::group_by(A) |>
  dplyr::summarise_all( e_coalesce_by_column )

erikerhardt/erikmisc documentation built on April 17, 2025, 10:48 a.m.