splitAsBumpyMatrix: Split to a BumpyMatrix

Description Usage Arguments Value Author(s) See Also Examples

View source: R/splitAsBumpyMatrix.R

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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 July 5, 2021, 2:21 a.m.