Checking if there exists a value in vector of dates that lies within a given range
This checks each of the two conditions and then ANDs them.
any( dates >= given_date - 150 & dates < given_date ) &
any( dates >= given_date - 300 & dates < given_date - 150 )
## [1] TRUE
Update
Fixed.
We can use between
in dplyr
or data.table
library(dplyr)
any(between(dates, given_date - 150, given_date)) &&
any(between(dates, given_date - 300, given_date - 150))
#[1] TRUE