1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
## METHODS FOR GENERIC: which
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setMethod("which", c(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", c(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", c(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", c(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", c(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", c(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", c(x = "nsparseVector"),
function(x, arr.ind = FALSE, useNames = TRUE) x@i)
setMethod("which", c(x = "lsparseVector"),
function(x, arr.ind = FALSE, useNames = TRUE) x@i[which(x@x)])
setMethod("which", c(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
})
|