Skip to contents

The filter() function is sused to subset an object, returing the observations that satisfy your conditions. An observation must return TRUE for all conditions within a context to be retained. Note, to guarantee a valid SummarizedExperiment is returned, filtering in the assays evaluation context is disabled.

Usage

# S3 method for class 'SummarizedExperiment'
filter(.data, ..., .preserve = FALSE)

Arguments

.data

A SummarizedExperiment object

...

conditions to filter on. These must be wrapped in cols() and or rows()

.preserve

Relevant when the .data input is grouped. If .preserve = FALSE (the default), the grouping structure is recalculated based on the resulting data, i.e. the number of groups may change.

Value

an object inheriting SummarizedExperiment class

Examples

# example code
filter(se_simple,
       rows(length > 30),
       cols(condition == "drug"))
#> class: SummarizedExperiment 
#> dim: 3 2 
#> metadata(0):
#> assays(2): counts logcounts
#> rownames(3): row_3 row_4 row_5
#> rowData names(3): gene length direction
#> colnames(2): col_3 col_4
#> colData names(2): sample condition
 
filter(se_simple,
       rows(rowSums(.assays_asis$counts) > 40),
       cols(colSums(.assays_asis$counts) < 50))
#> class: SummarizedExperiment 
#> dim: 3 3 
#> metadata(0):
#> assays(2): counts logcounts
#> rownames(3): row_3 row_4 row_5
#> rowData names(3): gene length direction
#> colnames(3): col_2 col_3 col_4
#> colData names(2): sample condition

# assay context is disabled
filter(se_simple,
       counts > 12) |> try()
#> Error in filter(se_simple, counts > 12) : 
#>   Cannot filter in `assays` context
#>  review expression indices 1 in dots
#>  consider wrapping expressions in rows(...) or cols(...)

# convert to `data.frame` first
as.data.frame(se_simple) |>
  filter(counts > 12)
#> Error in as.vector(x): no method for coercing this S4 class to a vector