Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rcumsum

Computes the prior to or reverse cumulative sum of a vector.


Description

Computes the prior-to (i.e., the cumulative sum prior to but not including the current value) or the reverse (i.e., the number that large or larger) cumulative sum of a vector. Also works for 1-dimensional tables, matrices, and data.frames, though it is best used with vectors.

Usage

rcumsum(x)

pcumsum(x)

Arguments

x

a numeric object.

Value

A numeric vector that contains the prior-to or reverse cumulative sums.

Note

An NA in the vector causes all returned values at and after the first NA for pcumsum and at and before the last NA for rcumsum to be NA. See the examples.

Author(s)

Derek H. Ogle, derek@derekogle.com

See Also

Examples

## Simple example
cbind(vals=1:10,
      cum=cumsum(1:10),
      pcum=pcumsum(1:10),
      rcum=rcumsum(1:10))

## Example with NA
vals <- c(1,2,NA,3)
cbind(vals,
      cum=cumsum(vals),
      pcum=pcumsum(vals),
      rcum=rcumsum(vals))

## Example with NA
vals <- c(1,2,NA,3,NA,4)
cbind(vals,
      cum=cumsum(vals),
      pcum=pcumsum(vals),
      rcum=rcumsum(vals))
      
## Example with a matrix
mat <- matrix(c(1,2,3,4,5),nrow=1)
cumsum(mat)
pcumsum(mat)
rcumsum(mat)

## Example with a table (must be 1-d)
df <- sample(1:10,100,replace=TRUE)
tbl <- table(df)
cumsum(tbl)
pcumsum(tbl)
rcumsum(tbl)

## Example with a data.frame (must be 1-d)
df <- sample(1:10,100,replace=TRUE)
tbl <- as.data.frame(table(df))[,-1]
cumsum(tbl)
pcumsum(tbl)
rcumsum(tbl)

FSA

Simple Fisheries Stock Assessment Methods

v0.8.32
GPL (>= 2)
Authors
Derek Ogle [aut, cre] (<https://orcid.org/0000-0002-0370-9299>), Powell Wheeler [aut], Alexis Dinno [aut] (Provided base functionality of dunnTest())
Initial release
2021-1-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.