I have a framework with multiple columns, and I want to replace NA in the same column if they are between two rows with the same number. Here are my details:
v1 v2
1 2
NA 3
NA 2
1 1
NA 7
NA 2
3 1
Basically, I want to start at the beginning of the data frame and replicate the NA in v1 column with the previous Non NA if the next Non NA matches the previous. That was said, I want the result to be like this:
v1 v2
1 2
1 3
1 2
1 1
NA 7
NA 2
3 1
As you can see, lines 2 and 3 are replaced by the number “1” because lines 1 and 4 have the same number, but lines 5.6 remain unchanged because the non na values in lines 4 and 7 are not identical. I played a lot, but so far no luck. Thanks
source
share