name direction type
Anna up single
Liam up divorced
Ryan down single
Aida updown married
Rita down single
Lita downup bachelorette
if the direction "above" your row contains the word "down" (as is the case with Aida and Lita), and your row contains the letters "up" then we must 1)change direction to "down" and 2)the type must also be changed to "CHANGED"
is there an easy way to do this? thank you.
what I want:
name direction type direction_new type_new
Anna up single up single
Liam up divorced up divorced
Ryan down single down single
Aida updown married down CHANGED
Rita down single down single
Lita downup bachelorette down CHANGED
Instead of ifelse I used case_when(), which I like very much.
The reasoning is that I create a lag that allows for a comparison with the row above, coalesce it to avoid the first row to have an NA.
Then I use case_when with the conditions you highlighted and eliminate the lagged column.