I'm attempting to remove all rows that come after a value (or values) but am running into some trouble.
I want to do the opposite of this: Filter to remove all rows before the first time a particular value in a specific column appears
Using the example dataframe from the above question:
(dat<-data.frame(a= c("pete", "mike", "bob", "bart", "bob"), b=c(1,2,3,4,5), c=c("home", "away", "home", "away", "gone")))
a b c
1 pete 1 home
2 mike 2 away
3 bob 3 home
4 bart 4 away
5 bob 5 gone
I want my result to look like this:
a b c
1 pete 1 home
2 mike 2 away
3 bob 3 home
Here is what I've tried so far:
dat %>% slice(which.min(a == "bob") : n())
But unlike which.max
which removed everything before bob
this doesn't remove anything after it.