I need to update the object values == "fix" so that they update to the value of the proceeding value in the same variable. My problem is that when the previous value was also == "fix" it doesn't see the updated value (because clearly it hasn't updated yet, why not?). I'm afraid I don't have the vocabulary to ask the proper question, so here's what it looks like.
So if this is my data frame(df):
row x
1 a
2 b
3 fix
4 fix
5 fix
6 b
7 a
8 fix
9 fix
I run my code:
df$x2 <- ifelse( df$x=="fix",lag(df$x2),df$x)
I get this:
row x x2
1 a a
2 b b
3 fix b
4 fix fix
5 fix fix
6 b b
7 a a
8 fix a
9 fix fix
But what I want is this:
row x x2
1 a a
2 b b
3 fix b
4 fix b
5 fix b
6 b b
7 a a
8 fix a
9 fix a
Any help would be appreciated (including on how to better frame the question and/or title of my question).