coalesce.na: Replaces NA values

Description Usage Arguments Value Examples

View source: R/coalesce_na.R

Description

This (vectorized) function returns the first non-NA argument, similar to the SQL function COALESCE. If a vector or matrix is passed as first argument, the remaining arguments are recycled to generate a vector/matrix of the same dimension, and coalescing is done element by element.

Usage

1

Arguments

x

The first value to coalesce.

...

Other values to coalesce.

Value

A vector of the same length as x.

Examples

1
2
3
4
5

Example output

[1] -1
[1] 5
[1]  1  2 NA
Warning message:
In coalesce.na(c(1, NA, NA), c(NA, 2)) :
  object length is not a multiple of first object length
     [,1] [,2]
[1,]   NA    2
[2,]    1    3
[1] NA

kimisc documentation built on May 2, 2019, 6:09 p.m.