splitAsBumpyMatrix: Split to a BumpyMatrix

View source: R/splitAsBumpyMatrix.R

splitAsBumpyMatrixR Documentation

Split to a BumpyMatrix

Description

Split a vector or Vector into a BumpyMatrix based on row/column factors. This facilitates the construction of a BumpyMatrix from vector-like objects.

Usage

splitAsBumpyMatrix(x, row, column, sparse = FALSE)

Arguments

x

A vector or Vector object, most typically a DFrame.

row

An object coercible into a factor, of length equal to x. This defines the row index for each element of x.

column

An object coercible into a factor, of length equal to x. This defines the column index for each element of x.

sparse

Logical scalar indicating whether a sparse representation should be used.

Value

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.

Author(s)

Aaron Lun

See Also

BumpyMatrix, if a CompressedList has already been constructed.

unsplitAsDataFrame, which reverses this operation to recover a long-format DataFrame.

splitAsList, which inspired this function.

Examples

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,]


LTLA/BumpyMatrix documentation built on Dec. 27, 2024, 9:28 a.m.