suppose I have a dataset like this
df <- data.frame(group = c(rep(1,3),rep(2,2), rep(3,2),rep(4,3),rep(5, 2)), score = c(30, 10, 22, 44, 6, 5, 20, 35, 2,
dplyr::filter(df, group == lag(group)) group score 1 1 10 2 1 22 3 2 6 4 3 20 5 4 2 6 4 60 7 5 5
See lead and lag of package dplyr for more information:
lead
lag
dplyr
https://dplyr.tidyverse.org/reference/lead-lag.html