File: mm-redo.R

package info (click to toggle)
rmatrix 0.95.5-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,732 kB
  • ctags: 2,028
  • sloc: ansic: 22,357; makefile: 74; sh: 28
file content (24 lines) | stat: -rw-r--r-- 716 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library(Matrix)

### Rebuild the 'mm' example matrix
### Use this if classes are changed

mmT <- as(mm, "dgTMatrix")
str(mmT)
mm3 <- cbind(i = mmT@i, j = mmT@j, x = mmT@x)
write.table(mm3, file = "mm-Matrix.tab", row.names=FALSE)# -> ASCII version

str(mmr <- read.table("mm-Matrix.tab", header = TRUE))
mmr$i <- as.integer(mmr$i)
mmr$j <- as.integer(mmr$j)

mmN <- with(mmr, new("dgTMatrix", Dim = c(max(i)+1:1,max(j)+1:1),
                     i = i, j = j, x = x))

stopifnot(identical(mmT, mmN)) # !!
## weaker (and hence TRUE too):
stopifnot(all.equal(as(mmN, "matrix"),
                    as(mmT, "matrix"), tol=0))

mm <- as(mmN, "dgCMatrix")
## save(mm, file = "....../Matrix/data/mm.rda", compress = TRUE)