Skip to contents

We can subset samples by indexing into a mediation dataset. It will subsample all fields – pretreatments, treatments, mediators, and outcomes. Note that there is no way to subset columns in this way, since they would be different across each source.

Usage

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

Arguments

x

An object of class mediation_data whose samples we want to subset.

i

An integer or integer/logical vector specifying the samples to subset to.

j

A placeholder to argree with R's [ function. Never used.

...

A placeholder to agree with R's [ function. Never used.

drop

A placeholder to agree with R's [ function. Never used.

Value

A version of the input mediation_data object whose @mediators, @outcomes, @treatments, and @pretreatments rows have all been subsetted according to i.

Examples

exper <- demo_joy() |>
    mediation_data("PHQ", "treatment", starts_with("ASV"))
exper[1]
#> [Mediation Data] 
#> 1 samples with measurements for, 
#> 1 treatment: treatment 
#> 5 mediators: ASV1, ASV2, ... 
#> 1 outcome: PHQ 
exper[1:10]
#> [Mediation Data] 
#> 10 samples with measurements for, 
#> 1 treatment: treatment 
#> 5 mediators: ASV1, ASV2, ... 
#> 1 outcome: PHQ