Hey there,

I have a dataset that contains the age (years) of participants and relationship duration (month). I want to create a condition where the datapoints of participants who where younger than 216 month aka 18 yr old, get excluded from the set. So it would need to be something like age - relationship_duration = > 216 month otherwise exclusion.

I can't seem to find my way around the obstacle of connecting the two variables to make it a condition and couldn't really find any solution online. Thanks !

Is this the kind of thing you're looking for? I've given a "base R" method and one using {dplyr}.

# BASE

df <- data.frame(
  dur = seq(0, 500, 50),
  age = seq(0, 1000, 100)
)

df[df$age - df$dur >= 216,]
#>    dur  age
#> 6  250  500
#> 7  300  600
#> 8  350  700
#> 9  400  800
#> 10 450  900
#> 11 500 1000

# TIDYVERSE

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

tibble(
  dur = seq(0, 500, 50),
  age = seq(0, 1000, 100)
) %>%
  filter(age - dur >= 216)
#> # A tibble: 6 × 2
#>     dur   age
#>   <dbl> <dbl>
#> 1   250   500
#> 2   300   600
#> 3   350   700
#> 4   400   800
#> 5   450   900
#> 6   500  1000

Created on 2022-07-30 by the reprex package (v2.0.1)

This was really helpful - thanks so much!