psum {statisfactory}R Documentation

Element-by-element sum

Description

This function is similar to pmax or pmin, except that it returns the element-wise sum of values. If the input is a matrix or data.frame, the output is the same as colSums.

Usage

psum(..., na.rm = FALSE)

Arguments

...

A set of vectors of the same length, a matrix, or a data.table.

na.rm

If FALSE (default), return NA if any element in a set is NA.

Details

Adapted from answer by Ben Bolker on StackOverflow.

Value

A numeric vector.

Examples


x1 <- 1:10
x2 <- runif(10)
psum(x1, x2)

x <- cbind(x1, x2)
psum(x)

x2[3] <- NA
psum(x1, x2)
psum(x1, x2, na.rm=TRUE)


[Package statisfactory version 1.0.4 Index]