For each unique id
, I want to find the max(G)
and then repeat it in a new column called G2
.
Is this possible in BASE R?
Here is a toy input and its desired output:
INPUT = data.frame(id = c(1,1,2,2,2), G = 1:5)
# id G
#1 1 1
#2 1 2
#3 2 3
#4 2 4
#5 2 5
DESIRED_OUTPUT = data.frame(id = c(1,1,2,2,2), G = 1:5, G2 = c(3,3,5,5,5))
# id G G2
#1 1 1 2
#2 1 2 2
#3 2 3 5
#4 2 4 5
#5 2 5 5