Describe the bug
Rfast::rowRanks(..., method = "min") returns incorrect results for rows with constant values. For example, a row with all identical values returns 1 1 1 0 instead of all equal ranks. I also observed that rowRanks() may crash R on a single-column matrix.
To Reproduce
library(Rfast)
x = matrix(rep(5, 4), nrow = 1)
Rfast::rowRanks(x, method = "min")
t(apply(x, 1, rank, ties.method = "min"))
This gives:
[,1] [,2] [,3] [,4]
[1,] 1 1 1 0
while base R gives:
[,1] [,2] [,3] [,4]
[1,] 1 1 1 1
I also observed a crash with a single-column matrix:
z = matrix(c(5, 5, 5, 5), ncol = 1)
Rfast::rowRanks(z, method = "min")
On my machine this causes a segfault.
Expected behavior
For a row where all values are equal, all returned ranks should also be equal. So for
matrix(rep(5, 4), nrow = 1)
I expect:
[,1] [,2] [,3] [,4]
[1,] 1 1 1 1
which matches:
t(apply(x, 1, rank, ties.method = "min"))
Desktop :
OS: macOS
R version 4.3.1
Rfast-Version: 2.1.5.1
Additional context
I encountered this while using rowRanks() for row-wise ranking with ties. I also observed similar behavior in colRanks(method = "min"), where constant columns do not appear to be handled correctly.
Describe the bug
Rfast::rowRanks(..., method = "min") returns incorrect results for rows with constant values. For example, a row with all identical values returns 1 1 1 0 instead of all equal ranks. I also observed that rowRanks() may crash R on a single-column matrix.
To Reproduce
library(Rfast)
x = matrix(rep(5, 4), nrow = 1)
Rfast::rowRanks(x, method = "min")
t(apply(x, 1, rank, ties.method = "min"))
This gives:
[,1] [,2] [,3] [,4]
[1,] 1 1 1 0
while base R gives:
[,1] [,2] [,3] [,4]
[1,] 1 1 1 1
I also observed a crash with a single-column matrix:
z = matrix(c(5, 5, 5, 5), ncol = 1)
Rfast::rowRanks(z, method = "min")
On my machine this causes a segfault.
Expected behavior
For a row where all values are equal, all returned ranks should also be equal. So for
matrix(rep(5, 4), nrow = 1)
I expect:
[,1] [,2] [,3] [,4]
[1,] 1 1 1 1
which matches:
t(apply(x, 1, rank, ties.method = "min"))
Desktop :
OS: macOS
R version 4.3.1
Rfast-Version: 2.1.5.1
Additional context
I encountered this while using rowRanks() for row-wise ranking with ties. I also observed similar behavior in colRanks(method = "min"), where constant columns do not appear to be handled correctly.