Row and Column Extremes of Sparse Matrices
rowMins.RdCompute the minimum or maximum of each row or column of a sparse matrix
of class spam.
Value
A numeric vector of length nrow(x) for rowMins
and rowMaxs, or of length ncol(x) for colMins
and colMaxs.
Details
For spam objects, the computation is performed by an efficient
Fortran routine operating directly on the compressed sparse row (CSR)
storage format.
The treatment of structural zeros (entries not stored in the sparse
representation) depends on the option spam.structurebased:
If
TRUE, structural zeros are ignored and only stored entries are considered. The fill value isInfforrowMins/colMinsand-InfforrowMaxs/colMaxs. A row or column with no stored entries returnsInfor-Infrespectively.If
FALSE, structural zeros are treated as real zeros and the fill value is0.
For non-spam objects, the functions fall back to
apply(x, 1, min) etc. If the matrixStats package is
loaded, its optimized implementations are used for non-spam
objects instead.
getOption("spam.NAOK") is ignored.
See also
rowSums, rowMeans for other row/column
summaries of spam objects.
rowMins in package matrixStats for
the generic these methods dispatch from when matrixStats is
loaded.
spam.options for the spam.structurebased option.
Examples
## create a small spam matrix
x <- spam(c(1, 0, 3, 0, 5, 0, 7, 0, 9), nrow=3, ncol=3)
rowMins(x)
#> [1] 1 5 3
rowMaxs(x)
#> [1] 7 5 9
pad(x) <- c(4, 4)
## effect of spam.structurebased
op <- options()
options(spam.structurebased=FALSE)
colMins(x) # structural zeros treated as 0
#> [1] 1 5 7 0
colMaxs(x)
#> [1] 3 5 9 0
options(spam.structurebased=TRUE)
colMins(x) # structural zeros ignored
#> [1] 1 5 7 Inf
colMaxs(x)
#> [1] 3 5 9 -Inf
options(op)