View source: R/split-matrix-methods.R
split_matrix_col | R Documentation |
This function also works with SummarizedExperiment::SummarizedExperiment()
/ SingleCellExperiment::SingleCellExperiment()
split_matrix_col(m, i) lapply_attr(X, FUN, ...) split_matrix_row(m, i) unsplit_matrix(x)
m |
|
i |
|
X |
a vector (atomic or list) or an |
FUN |
the function to be applied to each element of |
... |
optional arguments to |
x |
a list, typically returned from |
list of matrices of length(unique(i))
lapply_attr
: lapply and preserve attributes. Necessary for unsplit_matrix
.
split_matrix_row
: split a matrix by row
unsplit_matrix
: reverse a split (cbind/rbind) and reordering
m = matrix(1:12, nrow = 3) s_col = split_matrix_col(m, c('A', 'A', 'B', 'B')) s_row = split_matrix_row(m, c('B', 'A', 'B')) scaled = lapply_attr(s_col, function(x) x/sum(x)) unsplit_matrix(scaled) stopifnot(all.equal(unsplit_matrix(s_row), m))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.