File: base-matrix-fun.R

package info (click to toggle)
rmatrix 0.9975-6-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,136 kB
  • ctags: 2,162
  • sloc: ansic: 35,914; makefile: 225; fortran: 151; sh: 67
file content (41 lines) | stat: -rw-r--r-- 1,343 bytes parent folder | download | duplicates (2)
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
#### Thanks to the manipulation in base namespace, see  ../R/zzz.R ,
#### all the functions (in 'base' or namespaces that import it)
#### starting with something like
####	" x <- as.matrix(x) "  or   " X <- as.array(X) "
#### will work for 'Matrix'-matrices

library(Matrix)

data(KNex); mm <- KNex$mm
str(m1 <- mm[1:500, 1:200])
m11 <- m1[1:100, 1:20]
## These now work thanks to using our as.matrix():
str(D1 <- dist(m11))
str(rs <- apply(m1, 1, sum))

stopifnot(identical(kappa(Matrix(2:5, 2)),
                    kappa(matrix(2:5, 2))))
## used to seg.fault, PR#7984,
## because qr() was calling the wrong as.matrix()

## also matplot() or pairs().

## a regression test for  as.matrix.dist(.) still working
stopifnot(c(43, 43) == dim(as.matrix(d <- dist(USJudgeRatings))))

m <- Matrix(0:5, 3, 2)
(m2 <- Matrix(diag(c(3,1))))
(m3 <- crossprod(t(m))) # <- that's an S4 method; nothing "base"

str( svd(m) )
str( lapply(eigen(m3), zapsmall))

### outer()  used to work thanks to  as.array() -- up to R 2.2.1
##  no longer, because the definition of outer has changed
##stopifnot(identical(outer(m, m2),
##                    outer(as(m,"matrix"), as(m2,"matrix"))),
##          identical(outer(m3, m2),
##                    outer(as(m3,"matrix"), as(m2,"matrix"))))


cat('Time elapsed: ', proc.time(),'\n') # for ``statistical reasons''