File: which.R

package info (click to toggle)
rmatrix 1.7-5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,156 kB
  • sloc: ansic: 97,207; makefile: 280; sh: 165
file content (60 lines) | stat: -rw-r--r-- 2,224 bytes parent folder | download | duplicates (3)
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
          })