R/psum.R

Defines functions psum

Documented in psum

#' Parallel sum
#' 
#' This functin is to \link{sum}, what \link{pmin} and \link{pmax} is to \link{min} and \link{max}.
#' 
#' @param ... numeric vectors
#' @param na.rm a logical indicating whether missing values should be removed.
#' @export
#' @examples
#' psum(1:10, 1:10, 1:10) 
psum <- function(..., na.rm = FALSE) { 
  dat         <- do.call(cbind, list(...))
  res         <- rowSums(dat, na.rm = na.rm) 
  idx_na      <- !rowSums(!is.na(dat))
  res[idx_na] <- NA
  res 
}

Try the rccmisc package in your browser

Any scripts or data that you put into this service are public.

rccmisc documentation built on May 2, 2019, 2:48 p.m.