# rowMax(X, ignore.zero = FALSE) is the same as apply(X, 1, max)
X <- rSparseMatrix(1e4, 1e4, 1e5)
system.time(m1 <- rowMax(X, ignore.zero = FALSE))
system.time(m2 <- apply(X, 1, max))
all.equal(as.vector(m1), m2)
# speed depends most strongly on the number of entries in the matrix
# also some performance loss with size of matrix
# up to 1e5 entries is still reasonably fast
X <- rSparseMatrix(1e7, 1e7, 1e5)
system.time(m <- rowMax(X))
X <- rSparseMatrix(1e7, 1e7, 1e6)
system.time(M <- rowMax(X)) # about ten times as slow
# apply is not feasably on such large matrices
# Error: problem too large...
m <- apply(X, 1, max)Run the code above in your browser using DataLab