I am trying to add a new column, with character strings based on another column, via an ifelse statement in dplyr. When the condition is met, I also want the following two rows to also show the same value.
I show an example from the mtcars dataset
mtcars %>%
mutate(type=ifelse(mpg>20,"Event", "No event")) %>%
mutate(type=ifelse(type=="Event", lead(type),`type`))
What I am trying to do here is produce a new column called type, which if the mpg>20, I want the row to state "event" and if not "no event". However, I also want the two rows following the mpg>20 also to show "Event", even if they don't meet the criteria.
Hope this makes sense