I want to remove from this df rows where m=f, and where t is within 4 of rows where that happen whatever the specific combination of s and b is.
s<- c(1,1,1,1,1,1,2,1)
b<- c(1,1,1,1,1,1,1,2)
m <- c("o","o","o","o","f","o","o","o")
data <- rnorm(8)
t <- c(1,2,3,4,5,7,8,9)
df<- as.data.frame(cbind(s,b,m,data,t))
So in this example I want to remove the row containing 'f' and the rows which contain t of value up to 4 more than this row (so t of 5 to 9), provided that their value of s and b is the same as the row where 'f' was. So in it should remove row 5 and 6, but not row 7 because s is different from where 'f' was detected and not row 8 because b is different.
Sorry it is quite a dense question, I haven't been able to formulate an attempt at it.