Learn R Programming

statisfactory (version 1.0.4)

psum: 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)

Value

A numeric vector.

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.

Examples

Run this code

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)

Run the code above in your browser using DataLab