I have a general problem in R. I wonder if there's a way to identify if a specific string value occurs after another specific string value within a group. The dataset is a time series. Each Group consist of 10 years.
I want something like the below, but instead of lag I wish to look at every year before " stringvalue1" within the group.
mutate(new_var = if_else(stringvar = "stringvalue1"& lag(stringvar) %in% c("stringvalue2", "stringvalue3"), "Match", "Not match"))
Help would be much appreciated!