Transformation to other sparse formats

Share:

Description

Transform between the spam sparse format to the matrix.csr format of SparseM and dgRMatrix format of Matrix

Usage

1
2
3
4
5

Arguments

x

sparse matrix of class spam, matrix.csr, dgRMatrix or dgCMatrix.

Details

We do not provide any S4 methods and because of the existing mechanism a standard S3 does not work.

The functions are based on require.

Notice that as.matrix.csr.spam should read as as."matrix.csr".spam.

Value

According to the call, a sparse matrix of class spam, matrix.csr, dgRMatrix or dgCMatrix.

Author(s)

Reinhard Furrer

See Also

triplet, Matrix or matrix.csr

Examples

 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
## Not run: 
S <- diag.spam(4)
R <- as.dgRMatrix.spam( S) 
C <- as.dgCMatrix.spam( S)
as.spam.dgCMatrix(C) 
slotNames(U)
slotNames(R)
# For column oriented sparse formats a transpose does not the job,
# as the slot names change.


# as.spam(R) does not work.

## End(Not run)

## Not run: 
# for transformations between SparseM and spam:
as.matrix.csr.spam <- function(x,...) {
    newx <- new("matrix.csr")
    slot(newx,"ra",check=FALSE) <- x@entries
    slot(newx,"ja",check=FALSE) <- x@colindices
    slot(newx,"ia",check=FALSE) <- x@rowpointers
    slot(newx,"dimension",check=FALSE) <- x@dimension
    return(newx)
  }       
U <- as.matrix.csr.spam( S) 

## End(Not run)

## Not run: 
# a dataset contained in Matrix
data(KNex)
as.spam.dgCMatrix(KNex$mm) 


## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.