Closed APavlides closed 7 years ago
IMHO it exactly provides what it should. Namely the cumulative maximum per column.
x <- matrix(12:1, nrow=4, ncol=3)
xOut <- matrixStats::colCummaxs(x)
will provide an example where the ouput is not the input.
@APavlides I think you're looking for is the matrixStats equivalent of pmax(x, rep(colMaxs(x), each = nrow(x)))
and pmax(x, rep(rowMaxs(x), times = ncol(x)))
. AFAIK this doesn't yet exist but could be implemented, perhaps called colPMaxs()
and rowPMaxs()
.
You're right, I misunderstood the output. Thanks for clarification. This is now the test:
x = matrix(c(3, 5, 2, 1, 6, 3, 7, 8, 1), ncol = 3)
xOut <- matrixStats::colCummaxs(x)
expectMat <- matrix(c(3, 5, 5, 1, 6, 6, 7, 8, 8), ncol = 3)
expect_equal(xOut, expectMat)
Please note the rich set of package tests in https://github.com/HenrikBengtsson/matrixStats/tree/master/tests/. For colCummaxs()
there are:
The tests below show the bug. Instead of returning either a matrix of min's or max's for each column or row, the function returns the input matrix.