I need to conditionally remove the first row of a group. I want to group by column gr, then remove the first row of each group only if the first row of the group has value a
e.g.
gr value
1 b
1 c
1 a
2 a
2 d
3 b
3 a
3 h
3 a
4 a
4 a
4 g
Would become:
gr value
1 b
1 c
1 a
2 d
3 b
3 a
3 h
3 a
4 a
4 g
I know how to remove first row of groups:
library(dplyr)
df <- df %>% group_by(a) %>% slice(2:n()) %>% ungroup()
But I have no idea how to add the condition to only do this if of this first row, df$value = a
I'm new to R, it's still rather complicated to me, and I cannot find an answer to this problem anywhere.
Thank you very much!