ColumnLinkedMatrix-class: A Class for Linking Matrices by Columns or Rows

Description Details Methods See Also Examples

Description

This class treats a list of matrix-like objects that are linked together by columns (ColumnLinkedMatrix) or rows (RowLinkedMatrix) and have the same number of rows similarly to a regular matrix by implementing key methods such as [ and [<- for extracting and replacing matrix elements, dim to retrieve dimensions, and dimnames and dimnames<- to retrieve and set dimnames. Each list element is called a node and can be extracted or replaced using [[ and [[<-. A matrix-like object is one that has two dimensions and implements at least dim and [.

Details

Internally, this class is an S4 class that contains list. Each node can be accessed using the [[ operator. lapply is also possible. ColumnLinkedMatrix and RowLinkedMatrix form a class union called LinkedMatrix.

Methods

See Also

ColumnLinkedMatrix and RowLinkedMatrix to create a ColumnLinkedMatrix and RowLinkedMatrix objects from scratch. as.ColumnLinkedMatrix and as.RowLinkedMatrix to create a ColumnLinkedMatrix and RowLinkedMatrix objects from other objects. LinkedMatrix to create an empty, prespecified LinkedMatrix object. nNodes to get the number of nodes of a LinkedMatrix object.

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
37
38
39
40
41
# Create various matrix-like objects that correspond in dimensions
m1 <- ff::ff(initdata = rnorm(50), dim = c(5, 10))
m2 <- bigmemory::big.matrix(init = rnorm(50), nrow = 5, ncol = 10)
m3 <- matrix(data = rnorm(50), nrow = 5, ncol = 10)

# Link random matrices by columns
cm <- ColumnLinkedMatrix(m1, m2, m3)
dim(cm)

# Link random matrices by rows
rm <- RowLinkedMatrix(m1, m2, m3)
dim(rm)

# Get the number of nodes of each linked matrix
nNodes(cm)
nNodes(rm)

# Extract specific rows of linked matrix
cm[1, ]
cm[1:3, ]
rm[1, ]
rm[1:3, ]

# Extract specific columns of linked matrix
cm[, 1]
cm[, 1:3]
rm[, 1]
rm[, 1:3]

# Extract specific rows and columns of linked matrix
cm[1, 1]
cm[1:3, 1:3]
rm[1, 1]
rm[1:3, 1:3]

# Get a reference to one of the nodes
n <- cm[[2]]
class(n) == "big.matrix"

# LinkedMatrix objects are matrix-like and can be nested
rcm <- RowLinkedMatrix(cm, cm)

QuantGen/LinkedMatrix documentation built on May 28, 2020, 10:51 p.m.