R/rowCumsums.R
rowCumsums.RdCumulative sums, products, minima and maxima for each row (column) in a matrix.
rowCumsums(x, rows = NULL, cols = NULL, dim. = dim(x), ...,
useNames = TRUE)
colCumsums(x, rows = NULL, cols = NULL, dim. = dim(x), ...,
useNames = TRUE)
rowCumprods(x, rows = NULL, cols = NULL, dim. = dim(x), ...,
useNames = TRUE)
colCumprods(x, rows = NULL, cols = NULL, dim. = dim(x), ...,
useNames = TRUE)
rowCummins(x, rows = NULL, cols = NULL, dim. = dim(x), ...,
useNames = TRUE)
colCummins(x, rows = NULL, cols = NULL, dim. = dim(x), ...,
useNames = TRUE)
rowCummaxs(x, rows = NULL, cols = NULL, dim. = dim(x), ...,
useNames = TRUE)
colCummaxs(x, rows = NULL, cols = NULL, dim. = dim(x), ...,
useNames = TRUE)A vector indicating subset of rows to
operate over. If NULL, no subsetting is done.
A vector indicating subset of columns to
operate over. If NULL, no subsetting is done.
An integer vector of
length two specifying the dimension of x, also when not a
matrix. Comment: The reason for this argument
being named with a period at the end is purely technical (we get a run-time
error if we try to name it dim).
Not used.
If TRUE (default), names
attributes of the result are set, otherwise not.
Returns a numeric NxK matrix
of the same mode as x, except when x is of mode
logical, then the return type is
integer.
x <- matrix(1:12, nrow = 4, ncol = 3)
print(x)
#> [,1] [,2] [,3]
#> [1,] 1 5 9
#> [2,] 2 6 10
#> [3,] 3 7 11
#> [4,] 4 8 12
yr <- rowCumsums(x)
print(yr)
#> [,1] [,2] [,3]
#> [1,] 1 6 15
#> [2,] 2 8 18
#> [3,] 3 10 21
#> [4,] 4 12 24
yc <- colCumsums(x)
print(yc)
#> [,1] [,2] [,3]
#> [1,] 1 5 9
#> [2,] 3 11 19
#> [3,] 6 18 30
#> [4,] 10 26 42
yr <- rowCumprods(x)
print(yr)
#> [,1] [,2] [,3]
#> [1,] 1 5 45
#> [2,] 2 12 120
#> [3,] 3 21 231
#> [4,] 4 32 384
yc <- colCumprods(x)
print(yc)
#> [,1] [,2] [,3]
#> [1,] 1 5 9
#> [2,] 2 30 90
#> [3,] 6 210 990
#> [4,] 24 1680 11880
yr <- rowCummaxs(x)
print(yr)
#> [,1] [,2] [,3]
#> [1,] 1 5 9
#> [2,] 2 6 10
#> [3,] 3 7 11
#> [4,] 4 8 12
yc <- colCummaxs(x)
print(yc)
#> [,1] [,2] [,3]
#> [1,] 1 5 9
#> [2,] 2 6 10
#> [3,] 3 7 11
#> [4,] 4 8 12
yr <- rowCummins(x)
print(yr)
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 2 2 2
#> [3,] 3 3 3
#> [4,] 4 4 4
yc <- colCummins(x)
print(yc)
#> [,1] [,2] [,3]
#> [1,] 1 5 9
#> [2,] 1 5 9
#> [3,] 1 5 9
#> [4,] 1 5 9