# SCM Repository

[matrix] Diff of /pkg/tests/indexing.R
 [matrix] / pkg / tests / indexing.R

# Diff of /pkg/tests/indexing.R

revision 687, Fri Apr 1 07:36:09 2005 UTC revision 873, Sat Aug 27 21:26:23 2005 UTC
# Line 5  Line 5
5  identical3 <- function(x,y,z)   identical(x,y) && identical (y,z)  identical3 <- function(x,y,z)   identical(x,y) && identical (y,z)
6  identical4 <- function(a,b,c,d) identical(a,b) && identical3(b,c,d)  identical4 <- function(a,b,c,d) identical(a,b) && identical3(b,c,d)
7
8    ### Dense Matrices
9
10  m <- Matrix(1:28, nrow = 7)  m <- Matrix(1:28, nrow = 7)
11    validObject(m) ; m@x <- as.double(m@x) ; validObject(m)
12    stopifnot(identical(m, m[]),
13              identical(m[2, 3],  16), # simple number
14              identical(m[2, 3:4], c(16,23))) # simple numeric of length 2
15
16    m[2, 3:4, drop=FALSE] # sub matrix of class 'dgeMatrix'
17    m[-(4:7), 3:4]        # dito; the upper right corner of 'm'
18
19    ## rows or columns only:
20    m[1,]     # first row, as simple numeric vector
21    m[,2]     # 2nd column
22    m[,1:2]   # sub matrix of first two columns
23    m[-(1:6),, drop=FALSE] # not the first 6 rows, i.e. only the 7th
24
25    ## logical indexing
26    stopifnot(identical(m[2,3], m[(1:nrow(m)) == 2, (1:ncol(m)) == 3]),
27              identical(m[2,], m[(1:nrow(m)) == 2, ]),
28              identical(m[,3:4], m[, (1:4) >= 3]))
29
30    ## dimnames index (TODO)
31
32  ## TODO: not yet for dense matrices  ## TODO: more --- particularly once we have "m > 10" working!
33
34
35  ### Sparse Matrices  ### Sparse Matrices

Legend:
 Removed from v.687 changed lines Added in v.873