I am working with a longitudinal dataset with ID's, timestamps, and values. I would like to create a new variable for each individual that saves the value for the last timestamp for that individual in each of that individual's rows. For example, if my data looked like this:
ID Time Value
1 1:20 1
1 2:43 2
1 1:56 3
2 1:10 4
2 1:05 5
I would want to create a new variable Final_value as such:
ID Time Value Final_value
1 1:20 1 2
1 2:43 2 2
1 1:56 3 2
2 1:10 4 4
2 1:05 5 4
I prefer to use R's built-in methods. Perhaps there is a way to do this using the "ave" function?