Subsetting SCEs {SingleCellExperiment} | R Documentation

## SCE subsetting methods

### Description

Methods to subset SingleCellExperiment objects.

### Usage

    ## S4 method for signature 'SingleCellExperiment,ANY,ANY'
    x[i, j, ..., drop=TRUE]

    ## S4 method for signature 'SingleCellExperiment'
    subset(x, i, j)

    ## S4 replacement method for signature 'SingleCellExperiment,ANY,ANY,SingleCellExperiment'
    x[i, j] <- value

### Arguments

`x` | A SingleCellExperiment object.
`i, j` | A vector of logical or integer subscripts, indicating the rows and columns to be subsetted for `i` and `j`, respectively.
`...` | Extra arguments to be passed to `[,SummarizedExperiment-method`.
`drop` | A logical scalar that is ignored.
`value` | A SingleCellExperiment object with number of rows equal to length of `i` (or that of `x`, if `i` is not specified). The number of columns must be equal to the length of `j` (or number of columns in `x`, if `j` is not specified).

### Details

Subsetting yields a SingleCellExperiment object containing the specified rows (features) and columns (cells). Internal row and column metadata fields will also be subsetted so that methods such as `isSpike` are still valid. If column subsetting is performed, values of the `reducedDims` will be modified to retain only the selected cells.

Subset assignment will replace the assay values and metadata of the specified rows or columns in `x` with those in `value`. If both `i` and `j` are set, the relevant block of assay values will be replaced, along with the metadata for the affected rows and columns. If neither `i` or `j` are set, `x` will be turned into `value`.

### Value

For `[` and `subset`, a subsetted SingleCellExperiment object is returned.

For `[<-`, a modified SingleCellExperiment object is returned.

### Author(s)

Aaron Lun

### See Also

`SingleCellExperiment-class`

### Examples

    example(SingleCellExperiment, echo=FALSE) # using the class example

    sce[1:10,]
    sce[,1:5]

    sce2 <- sce
    sce2[1:10,] <- sce[11:20,]

    # Can also use subset()
    subset(sce, 1, 1)

    # Can also use split()
    split(sce, sample(LETTERS, nrow(sce), replace=TRUE))

[Package SingleCellExperiment version 1.2.0 Index]