xSparseMatrix: Function to create a sparse matrix for an input file with...

Description Usage Arguments Value Note See Also Examples

Description

xSparseMatrix is supposed to create a sparse matrix for an input file with three columns.

Usage

1
xSparseMatrix(input.file, rows = NULL, columns = NULL, verbose = T)

Arguments

input.file

an input file containing three columns: 1st column for rows, 2nd for columns, and 3rd for numeric values. Alternatively, the input.file can be a matrix or data frame, assuming that input file has been read. Note: the file should use the tab delimiter as the field separator between columns

rows

a vector specifying row names. By default, it is NULL

columns

a vector specifying column names. By default, it is NULL

verbose

logical to indicate whether the messages will be displayed in the screen. By default, it sets to TRUE for display

Value

an object of the dgCMatrix class (a sparse matrix)

Note

If rows (or columns) are not NULL, the rows (or columns) of resulting sparse matrix will be union of those from input.file and those from rows (or columns). None

See Also

xSparseMatrix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# create a sparse matrix of 4 X 2
input.file <- rbind(c('R1','C1',1), c('R2','C1',1), c('R2','C2',1),
c('R3','C2',1), c('R4','C1',1))
res <- xSparseMatrix(input.file)
res
# get a full matrix
as.matrix(res)

res <- xSparseMatrix(input.file, columns=c('C1','C2','C3'))
res

Example output

Loading required package: igraph

Attaching package: 'igraph'

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union

Loading required package: dnet
Loading required package: supraHex
Loading required package: hexbin
Loading required package: ggplot2
Load the input data matrix of 5 X 3 ...
There are 5 entries, converted into a sparse matrix of 4 X 2.
4 x 2 sparse Matrix of class "dgCMatrix"
   C1 C2
R1  1  .
R2  1  1
R3  .  1
R4  1  .
   C1 C2
R1  1  0
R2  1  1
R3  0  1
R4  1  0
Load the input data matrix of 5 X 3 ...
There are 5 entries, converted into a sparse matrix of 4 X 3.
4 x 3 sparse Matrix of class "dgCMatrix"
   C1 C2 C3
R1  1  .  .
R2  1  1  .
R3  .  1  .
R4  1  .  .

XGR documentation built on June 18, 2019, 3:01 p.m.

Related to xSparseMatrix in XGR...