Learn R Programming

preputils (version 1.0.3)

coalesce: select 1st existing value of several columns

Description

Inspired by the respectively named sql function. In a list of vectors with equal length the function for each of the observations selects the first value that is not NA, in the order provided

Usage

coalesce(...)

Arguments

...

vectors holding the values, sepearated by "," (commonly columns of data.frame)

Value

A named vector holding the supplemented values

Details

Data are transformed according to $$b=\frac{2^M}{2^M+1}$$

Examples

Run this code
# NOT RUN {
    a1 = c(1,NA,NA,NA)
    a2 = c(2,2,NA,NA)
    a3 = c(NA,3,3,NA)
    cbind(a1,a2,a3,suppl=coalesce(a1,a2,a3))
# }

Run the code above in your browser using DataLab