Would like to count the number of times a value in the whole column of DF2(DF2$B) recedes below each cell in DF1$A.
Example:
DF1 <- data.frame(Q=c("fun","fun"),
A=c(200,700))
DF2 <- data.frame(Z=as.Date(c("2023-10-01","2023-10-02","2023-10-03","2023-10-04")),
B=c(600,500,100,800))
Desired Output:
DF1$Counter <- c(1,3)
Make use of
findInterval
. Note that you have tosort
theDF2$B
column first