Learn R Programming

Rcplex (version 0.2-1)

simple_triplet_matrix: Create sparse matrix with triplet representation

Description

Create a sparse matrix, with entries stored by triplets (row,col,entry).

Usage

simple_triplet_matrix(i, j, v, nrow = max(i), ncol = max(j))

Arguments

i
Row indices of entries
j
Column indices of entries
v
Entries
nrow
Number of rows in matrix
ncol
Number of columns in matrix

Value

  • Returns S3-style object of class simple_triplet_matrix
  • iRow indices of entries
  • jColumn indices of entries
  • vEntries
  • nrowNumber of rows in matrix
  • ncolNumber of columns in matrix

Details

For usage in Rcplex, entries must be given in column major order, i.e. component j must be in ascending order

Examples

Run this code
## Define matrix
## 1 0 3
## 0 1 2
## 3 2 0
mat <- simple_triplet_matrix(
   i=c(1,3,2,3,1,3),
   j=c(1,1,2,2,3,3),
   v=c(1,3,1,2,3,2));
print(mat);

# coerce to matrix
as.matrix(mat);

# transpose
as.matrix(t(mat));

# indexing
mat[1,1];
mat[1,];

Run the code above in your browser using DataLab