Select rows of a data frame based on phenotypes or other expressions.

select_rows(csd, sel)

Arguments

csd

A data frame

sel

May be a character vector, a one-sided formula, a list containing such or NA. A character vector is interpreted as the name(s) of one or more phenotypes and selects any matching phenotype. A formula is interpreted as an expression on the columns of csd. Multiple list items are joined with AND. NA is interpreted as "select all". It is convenient for lists of selection criteria.

Value

A logical vector of length nrow(csd) which selects rows according to sel.

Details

select_rows implements a flexible mechanism for selecting cells (rows) from a cell segmentation table. Cells may be selected by single or multiple phenotype, by expression level, or combinations of both.

See the tutorial Selecting cells within a cell segmentation table for extensive documentation and examples.

See also

parse_phenotypes for a convenient way to create selectors for most common phenotypes.

Examples

csd <- sample_cell_seg_data

# Select tumor cells with PDL1 expression > 3
selector <- list('CK+', ~`Entire Cell PDL1 (Opal 520) Mean`>3)
pdl1_pos_tumor <- csd[select_rows(csd, selector),]
range(pdl1_pos_tumor$`Entire Cell PDL1 (Opal 520) Mean`)
#> [1]  3.007 47.459

# Select all T-cells. Note: Use c() to combine phenotypes, not list()
selector <- c('CD8+', 'FoxP3+')
tcells <- csd[select_rows(csd, selector),]
table(tcells$Phenotype)
#> 
#>   CD8+ FoxP3+ 
#>    228    228