colSums {Matrix} | R Documentation |
Form row and column sums and means for Matrix
objects.
colSums (x, na.rm = FALSE, dims = 1, ...) rowSums (x, na.rm = FALSE, dims = 1, ...) colMeans(x, na.rm = FALSE, dims = 1, ...) rowMeans(x, na.rm = FALSE, dims = 1, ...) ## S4 method for signature 'sparseMatrix': colSums(x, na.rm = FALSE, dims = 1, sparseResult = FALSE, ...) ## S4 method for signature 'sparseMatrix': rowSums(x, na.rm = FALSE, dims = 1, sparseResult = FALSE, ...) ## S4 method for signature 'sparseMatrix': colMeans(x, na.rm = FALSE, dims = 1, sparseResult = FALSE, ...) ## S4 method for signature 'sparseMatrix': rowMeans(x, na.rm = FALSE, dims = 1, sparseResult = FALSE, ...)
x |
a Matrix, i.e., inheriting from Matrix . |
na.rm |
logical. Should missing values (including NaN )
be omitted from the calculations? |
dims |
completely ignored by the Matrix methods. |
... |
potentially further arguments, for method <->
generic compatibility. |
sparseResult |
logical indicating if the result should be sparse,
i.e., inheriting from class sparseVector . |
returns a numeric vector if sparseResult
is FALSE
as per
default. Otherwise, returns a sparseVector
.
colSums
and the
sparseVector
classes.
(M <- bdiag(Diagonal(2), matrix(1:3, 3,4), diag(3:2))) colSums(M) d <- Diagonal(10, c(0,0,10,0,2,rep(0,5))) MM <- kronecker(d, M) dim(MM) # 40 140 cm <- colSums(MM) (scm <- colSums(MM, sparseResult = TRUE)) stopifnot(is(scm, "sparseVector"), identical(cm, as.numeric(scm))) rowSums(MM, sparseResult = TRUE) # 8 of 40 are not zero if(FALSE) ## FIXME! -- requires <sparseVec> / <scalar> rowMeans(MM, sparseResult = TRUE)