A2SM: A2SM: Convert a matrix A to sparse matrix object ASM

View source: R/qDEA.R

A2SMR Documentation

A2SM: Convert a matrix A to sparse matrix object ASM

Description

A2SM: Convert a matrix A to sparse matrix object ASM

Usage

A2SM(
  A,
  SMM = "CRI",
  ZINDEX = FALSE,
  eps = .Machine$double.eps,
  NA_flag = (-1e+12)
)

Arguments

A

The matrix A.

SMM

Sparse matrix method with SMM='A',CRI','RCI','CMO', or 'RMO'

ZINDEX

T = Use zero indexing or F = Use one indexing.

eps

Value to use in non-zero test.

NA_flag

Number to uses as NA flag

Value

A list object containing the matrix components:

nnz = the number of non-zero elements in ra.

nr = the number of rows in matrix A.

nc = the number of columns in matrix A.

ia = the row index.

ja = the column index.

ra = the non-zero coefficients in A

rnames = matrix row names – may be ""

cnames = matrix column names – may be ""

SMM = the sparse matrix type.

ZINDEX with T = Use zero indexing or F = Use one indexing.

Examples

(A = matrix(c(1,0,0,2,0,3,1,0,0,5,0,6),3,4,byrow=TRUE))
(ASM1 = A2SM(A,SMM='CMO',ZINDEX=TRUE))
(ASM2=SM2SM(ASM1,SMM2='CRI',ZINDEX2=FALSE))
SM2A(ASM1)
SM2A(ASM2)

(A = matrix(c(1,0,0,2,0,3,1,0,0,5,0,6),3,4,byrow=TRUE)); A[2,3]=NA; A
(ASM1 = A2SM(A,SMM='CMO',ZINDEX=TRUE)); A; SM2A(ASM1)
(ASM2 = SM2SM(ASM1,SMM2='CRI',ZINDEX2=TRUE)); A ; SM2A(ASM2)

#CMO  documentation example
nr=5
nc=8
ra=c(3.0,5.6,1.0,2.0,1.1,1.0,-2.0,2.8,-1.0,1.0,1.0,-1.2,-1.0,1.9)
ia=c(0,4,0,1,1,2,0,3,0,4,2,3,0,4)
ja=c(0,2,4,6,8,10,11,12,14)
SMM='CMO'
ZINDEX=TRUE
ASM=list(nr=nr,nc=nc,ra=ra,ia=ia,ja=ja,SMM=SMM,ZINDEX=ZINDEX)
(A=SM2A(ASM))

qDEA documentation built on April 13, 2026, 5:07 p.m.