revcumsum: Reverse Cumulative Sum

View source: R/utilseq.R

revcumsumR Documentation

Reverse Cumulative Sum

Description

Returns a vector of cumulative sums of the input values, running in reverse order. That is, the ith entry in the output is the sum of entries i to n in the input, where n is the length of the input.

Usage

revcumsum(x)

Arguments

x

A numeric or complex vector.

Details

This low-level utility function is a faster alternative to rev(cumsum(rev(x))) under certain conditions. It computes the reverse cumulative sum of the entries of x. If y <- revcumsum(x), then y[i] = sum(x[i:n]) where n = length(x).

This function should not be used if x could contain NA values: this would lead to an error.

Value

A vector of the same length and type as x.

Author(s)

\adrian

.

See Also

cumsum.

Examples

  revcumsum(1:5)
  rev(cumsum(rev(1:5)))
  x <- runif(1e6)
  system.time(rev(cumsum(rev(x))))
  system.time(revcumsum(x))

spatstat.utils documentation built on Oct. 24, 2023, 9:08 a.m.