Say I have data as follows
A <- c(1,1,1,2,2,2,3,3,3)
B <- c(1,0,0,1,0,0,1,0,0)
C <- c(8,7,6,8,7,8,9,9,11)
D <- data.frame(A,B,C)
D
library(dplyr)
E <- D %>%
group_by(B) %>%
filter(abs(diff(C)) <= 1)
to remove these cases, so that those shown in yellow are removed
in other words, for each a
identity, when we assess the b=0
relative to b=1
, any values where the c
exceeds difference of 1.