Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

coalesce

Replace NAs in parallel vectors


Description

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

Usage

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)

References

Examples

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

stackoverflow

Stack Overflow's Greatest Hits

v0.7.0
CC BY-SA 4.0
Authors
Neal Fultz <nfultz@gmail.com> and the StackOverflow.com community
Initial release
2020-01-03

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.