subset.Seurat: Subset 'Seurat' Objects

View source: R/seurat.R

subset.SeuratR Documentation

Subset Seurat Objects

Description

Subset Seurat Objects

Usage

## S3 method for class 'Seurat'
subset(
  x,
  subset,
  cells = NULL,
  features = NULL,
  idents = NULL,
  return.null = FALSE,
  droplevels.meta.data = FALSE,
  ...
)

## S3 method for class 'Seurat'
x[i, j, ...]

Arguments

x

A Seurat object

subset

Logical expression indicating features/variables to keep

cells, j

A vector of cell names or indices to keep

features, i

A vector of feature names or indices to keep

idents

A vector of identity classes to keep

return.null

If no cells are requested, return a NULL; by default, throws an error

droplevels.meta.data

logical, whether to drop unused factor levels from meta.data columns after subsetting. Default is FALSE.

...

Arguments passed to WhichCells

Value

subset: A subsetted Seurat object

[: object x with features i and cells j

Note

Subsetting with '[' does not guarantee preservation of the specified cell or feature ordering.

See Also

WhichCells

Seurat object, validity, and interaction methods $.Seurat(), Seurat-class, Seurat-validity, [[.Seurat(), [[<-,Seurat, [[<-,Seurat,NULL, dim.Seurat(), dimnames.Seurat(), merge.Seurat(), names.Seurat()

Examples

# `subset` examples
# subset using expression threshold (and optionally specify the layer to use)
subset(pbmc_small, subset = MS4A1 > 4)
subset(pbmc_small, subset = MS4A1 > 3, slot = 'counts')

# subset using expression threshold when "-" present in feature name
subset(pbmc_small, subset = `DLGAP1-AS1` > 2)

# subset using identity (invert keeps identities not specified)
subset(pbmc_small, idents = '0', invert = TRUE)

# subset retaining only specific set of features
subset(pbmc_small, features = VariableFeatures(object = pbmc_small))

# subset and drop unused levels from meta.data columns after subset
subset(pbmc_small, idents = '0', droplevels.meta.data = TRUE)

# `[` examples
pbmc_small[VariableFeatures(object = pbmc_small), ]
pbmc_small[, 1:10]


SeuratObject documentation built on April 11, 2026, 9:06 a.m.