Suppose I have the following column
**CurrentStatus**
Current
NoChange
NoChange
NoChange
NoChange
Late
I want to mutate it so that if the value is "NoChange" it uses the prior value.
I tried:
myDF %>% mutate(CurrentStatus = ifelse(CurrentStatus == "NoChange", lag(CurrentStatus), CurrentStatus)
That doesn't seem to work -- I think it's because it does a vectorized calculation so it looks at all the lags at the same time. I need it to "roll forward". I was wondering what's the most efficient way to do this without a for loop. I specifically want to avoid a for loop as there are some grouping variables not shown that I need to be mindful of.
Thanks!