This question is an extension of the answer to this and this Here's an example df:
name score end.s time
1 a 1 NA 1
2 a 2 NA 2
3 a 3 NA 3
4 b 4 4 1
5 b 5 4 2
6 b 6 4 3
7 c 7 NA 1
8 c 8 NA 2
9 d 6 6 1
10 d 7 6 3
And the output I would like:
name score end.s time
1 a 1 3 1
2 a 2 3 2
3 a NA 3 3
4 b 4 4 1
5 b 5 4 2
6 b 6 4 3
7 c 7 8 1
8 c NA 8 2
9 d 6 6 1
10 d 7 6 3
There are two features of the transformation - taking the last value from the 'score' column to replace the NAs in the 'end.s' column and replacing that value from the 'score' column with NA.
I thought that I could replace the NAs with using the syntax from the previous posts but it doesn't work out that way once I took a look and thought about it for a second.
I was thinking an apply function would be the way to go but I haven't even managed to muddle through the first step.