I have this df
df <- data.frame('ID' = c(1,1,1,1,1,3,4,4,4,5),
                 'YEAR' = c(2002,2002,2002,2003,2003,2005,2010,2010,2010,2008),
                 'WAGES' = c(100,98,60,120,80,300,50,40,30,500));
And I want to add a column to the df which has the WAGES as percentages of the max wage for each unique pair of YEAR and ID. Thus, the result should be like this:
R> df
   ID YEAR WAGES  PRC
1   1 2002   100 1.00
2   1 2002    98 0.98
3   1 2002    60 0.60
4   1 2003   120 1.00
5   1 2003    80 0.67
6   3 2005   300 1.00
7   4 2010    50 1.00
8   4 2010    40 0.80
9   4 2010    30 0.60
10  5 2008   500 1.00
 
     
    