https://github.com/cran/Matrix
Tip revision: 23d9d53f0b3c5fcd18cc73551fe6e531e08c9f0e authored by Martin Maechler on 14 November 2023, 11:55:00 UTC
version 1.6-3
version 1.6-3
Tip revision: 23d9d53
which.R
## METHODS FOR GENERIC: which
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setMethod("which", signature(x = "ndenseMatrix"),
function(x, arr.ind = FALSE, useNames = TRUE) {
wh <- which(.M2v(x))
if(arr.ind)
arrayInd(wh, x@Dim, dimnames(x), useNames = useNames)
else wh
})
setMethod("which", signature(x = "ldenseMatrix"),
function(x, arr.ind = FALSE, useNames = TRUE) {
wh <- which(.M2v(x))
if(arr.ind)
arrayInd(wh, x@Dim, dimnames(x), useNames = useNames)
else wh
})
setMethod("which", signature(x = "nsparseMatrix"),
function(x, arr.ind = FALSE, useNames = TRUE) {
wh <- .M2V(x)@i
if(arr.ind)
arrayInd(wh, x@Dim, dimnames(x), useNames = useNames)
else wh
})
setMethod("which", signature(x = "lsparseMatrix"),
function(x, arr.ind = FALSE, useNames = TRUE) {
wh <- { x. <- .M2V(x); x.@i[which(x.@x)] }
if(arr.ind)
arrayInd(wh, x@Dim, dimnames(x), useNames = useNames)
else wh
})
setMethod("which", signature(x = "ndiMatrix"),
function(x, arr.ind = FALSE, useNames = TRUE) {
wh <- .M2V(x)@i
if(arr.ind)
arrayInd(wh, x@Dim, x@Dimnames, useNames = useNames)
else wh
})
setMethod("which", signature(x = "ldiMatrix"),
function(x, arr.ind = FALSE, useNames = TRUE) {
wh <- { x. <- .M2V(x); x.@i[which(x.@x)] }
if(arr.ind)
arrayInd(wh, x@Dim, x@Dimnames, useNames = useNames)
else wh
})
setMethod("which", signature(x = "nsparseVector"),
function(x, arr.ind = FALSE, useNames = TRUE) x@i)
setMethod("which", signature(x = "lsparseVector"),
function(x, arr.ind = FALSE, useNames = TRUE) x@i[which(x@x)])
setMethod("which", signature(x = "indMatrix"),
function(x, arr.ind = FALSE, useNames = TRUE) {
wh <- .M2V(x)@i
if(arr.ind)
arrayInd(wh, x@Dim, x@Dimnames, useNames = useNames)
else wh
})