coalesce: Replace NAs in parallel vectors

Description Usage Arguments Value Changes Author(s) References Examples

View source: R/coalesce.R

Description

Replaces NA elements of x with corresponding element of y, and NA elements of that with corresponding element from dots.

Usage

1
coalesce(x, y, ...)

Arguments

x

a vector

y

replacement values

...

further replacement values

Value

x with NAs replaced with y

Changes

Rather than using eagerly evaluating the dot arguments and Reducing over them, instead we use recursion to evaluate them lazily.

Author(s)

Gregor Thomas,

References

https://stackoverflow.com/a/19254510/986793

Examples

1
2
3
4
x <- c(1:4, NA, 1:4, NA)
y <- c(1:9, NA)
z <- c(NA, NA, 1:8)
coalesce(x,y,z) 

stackoverflow documentation built on Jan. 10, 2020, 9:07 a.m.