| ColumnLinkedMatrix-class {LinkedMatrix} | R Documentation |
A Class for Linking Matrices by Columns or Rows
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
-
[ -
[<- -
dim -
dimnames -
dimnames<- -
as.matrix -
is.matrix -
length -
print -
str -
cbind(forColumnLinkedMatrix) -
rbind(forRowLinkedMatrix)
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
# 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)