I fully anticipate getting slammed for a duplicate question, but I just couldn't find a similar question. Apologies in advance.
I am trying to clean some data that sometimes contains a summary row and sometimes does not. here is a small reproducible example:
library(tidyverse)
yr <- c(2010, 2010, 2010,
2011, 2011, 2011, 2011,
2012, 2012, 2012)
a <- c("HAY", "APPLES", "PUMPKINS",
"HAY", "HAY & HAYLAGE", "APPLES", "PUMPKINS",
"HAY & HAYLAGE", "APPLES", "PUMPKINS")
b <- c(1:10)
dat <- as_tibble(list(yr = yr, a = a, b = b))
dat %>%
group_by(yr) %>%
filter(a != "HAY" if group contains a== "HAY & HAYLAGE")
obviously, that last line of code is pseudo code. In group for yr = 2011 I want to filter out the row where a equals "HAY". My resulting tibble should have 9 rows.