divideIntoBatches {batchelor} | R Documentation

## Divide into batches

### Description

Divide a single input object into multiple separate objects according to their batch of origin.

### Usage

    divideIntoBatches(x, batch, byrow = FALSE, restrict = NULL)

### Arguments

`x` | A matrix-like object where one dimension corresponds to cells and another represents features.
`batch` | A factor specifying the batch to which each cell belongs.
`byrow` | A logical scalar indicating whether rows correspond to cells.
`restrict` | A subsetting vector specifying which cells should be used for correction.

### Details

This function is intended for internal use and other package developers. It splits a single input object into multiple batches, allowing developers to use the same code for the scenario where `batch` is supplied with a single input.

### Value

A list containing:

- `batches`, a named list of matrix-like objects where each element corresponds to a level of `batch` and contains all cells from that batch.

- `reorder`, an integer vector to be applied to the combined `batches` to recover the ordering of cells in `x`.

- `restricted`, a named list of integer vectors specifying which cells are to be used for correction. Set to `NULL` if the input `restrict` was also `NULL`.

### Author(s)

Aaron Lun

### Examples

    X <- matrix(rnorm(1000), ncol=100)
    out <- divideIntoBatches(X, sample(3, 100, replace=TRUE))
    names(out)

    # Recovering original order.
    Y <- do.call(cbind, out$batches)
    Z <- Y[,out$reorder]
    all.equal(Z, X) # should be TRUE.

[Package batchelor version 1.2.4 Index]