R/coalesce.R

Defines functions coalesce

Documented in coalesce

#' Coalesce vectors
#' 
#' @description Returns the expression with the highest precedence that is nor missing. If all expressions are missing, the result is NA.
#'
#' @examples 
#' coalesce(c(NA,2,NA), c(1, NA, NA), c(NA, NA, 3))
#' @export






coalesce<-function(...){
  
  Reduce(function(x,y){
    i<-which(is.na(x))
    x[i]<-y[i]
    x
  },
  list(...))
  
}
JackStat/THMisc documentation built on May 7, 2019, 10:17 a.m.