coalesce_with_checks: Collapse multiple redundant columns into a single column

View source: R/coalesce_with_checks.R

coalesce_with_checksR Documentation

Collapse multiple redundant columns into a single column

Description

Collapse multiple columns with redundant information into a single column. This function is similar to dplyr::coalesce, but uses several checks and informative error messages. Specifically, it checks for more than one unique non-NA value in each row, and returns an error if there are any such rows (in similar cases, dplyr::coalesce uses the first non-NA value). It then takes, for each row, the unique non-NA value found in one or more of the input columns, and places that value into the first column.

Usage

coalesce_with_checks(x, columns, tol = .Machine$double.eps^0.5)

Arguments

x

data frame containing the redundant columns to be coalesced/collapsed

columns

character vector, the names of the columns to be coalesced/collapsed. The values will be combined into the first column listed in columns, and the remaining columns will be dropped.

tol

numeric, the tolerance for assuming identity of floating-point numeric values. Defaults to the square route of the machine tolerance

Value

A data frame with columns values collapsed into the first column listed.


mjdufort/miscHelpers documentation built on Feb. 4, 2024, 7:44 p.m.