I found that my question might be similar to this one, but I could figure out how to adjust it to my case.
I have one data set containing dates of an image and another one with the dates when it rained. I would like to remove images what were taken within 3 days after it rained.
E.g. For example:
df1 <- data.frame(c(1,2,3,4), as.Date(c("1934-05-20", "1934-05-03", "1934-05-04", "1934-05-01")))
names(df1) <- c('img', 'date')
df2 <- data.frame(c(3,8,64,5,7), as.Date(c("1934-05-27", "1934-05-25", "1934-05-15", "1934-05-04", "1934-05-02")))
names(df2) <- c('rain', 'date')
Giving us:
> df1
  img       date
1   1 1934-05-20
2   2 1934-05-04
3   3 1934-05-03
4   4 1934-05-01
> df2
   rain       date
1     3 1934-05-27
2     8 1934-05-25
3    64 1934-05-15
4     5 1934-05-04
5     7 1934-05-02
The output would look like:
img         date
  1   1934-05-20
  4   1934-05-01
UPD:
I have used dummy method, but it worked for me:
i <- 0
mylist <- c(0,0)
for (x in df1$Date){
  i <- i+1
  x <- as.Date(x, format="%Y-%m-%d", origin = "1970-01-01")
  yr <- format(as.Date(x, format="%Y-%m-%d", origin = "1970-01-01"),"%Y")
  r <- subset(df2, YY == yr)
  y <- x - r$Date
  s <- sum(y >= 0 & y <= 3)
  if (s == 0) {
    mylist[i] <- FALSE 
  } else {mylist[i] <- TRUE
  } 
}
dat <- df1[!mylist, ]
 
    