splitAsBumpyMatrix {BumpyMatrix} | R Documentation |
Split a vector or Vector into a BumpyMatrix based on row/column factors. This facilitates the construction of a BumpyMatrix from vector-like objects.
splitAsBumpyMatrix(x, row, column, sparse = FALSE)
x |
|
row |
An object coercible into a factor, of length equal to |
column |
An object coercible into a factor, of length equal to |
sparse |
Logical scalar indicating whether a sparse representation should be used. |
A BumpyMatrix of the appropriate type,
with number of rows and columns equal to the number of levels in row
and column
respectively.
Each entry of the matrix contains all elements of x
with the corresponding indices in row
and column
.
Aaron Lun
BumpyMatrix
, if a CompressedList has already been constructed.
unsplitAsDataFrame
, which reverses this operation to recover a long-format DataFrame.
splitAsList
, which inspired this function.
mat <- splitAsBumpyMatrix(runif(1000), row=sample(LETTERS, 1000, replace=TRUE), column=sample(10, 1000, replace=TRUE) ) mat mat[,1] mat[1,] # Or with a sparse representation. mat <- splitAsBumpyMatrix(runif(10), row=sample(LETTERS, 10, replace=TRUE), column=sample(10, 10, replace=TRUE) ) mat mat[,1] mat[1,]