Date: 2022-08-21 17:22 Sender: Mikael JaganIt would be "nice" if <sparseMatrix>[drop=TRUE] would return a sparseVector preserving structural zeros rather than a traditional vector, which does not distinguish between structural and nonstructural zeros.
However, I suspect that such a change would break a lot of existing code. I guess that we could provide utilities, e.g., getSparseRow() and getSparseCol(), with that functionality, rather than changing our methods for the extract operator `[`...
In the mean time, you can use these no-check versions:
getSparseRow <- function(x, i) {
d <- x@Dim
v <- as(x, "sparseVector")
k <- seq.int(from = i, by = d[1L], length.out = d[2L])
v[k]
}
getSparseCol <- function(x, j) {
m <- x@Dim[1L]
v <- as(x, "sparseVector")
k <- seq.int(from = 1 + (j - 1) * m, length.out = m)
v[k]
}
Then you could do (for example):
> (r <- getSparseRow(m, 2))
sparse vector (nnz/length = 2/3) of class "dsparseVector"
[1] . 100 100
> sd(r@x)
[1] 0 |