I have a data frame like the following (but much larger)
df<-data.frame(Claim=c("117","249","117","117","249","652"),ValuationDate=c("01/05/1965","01/05/1980","01/10/1965","01/20/1965","01/30/1980","01/10/1990"))
df
Claim ValuationDate
1 117 01/05/1965
2 249 01/05/1980
3 117 01/10/1965
4 117 01/20/1965
5 249 01/30/1980
6 652 01/10/1990
I want to add a column, "ValuationNumber" which is 1 for the earliest valuation date for each claim, and increases by 1 for each subsequent valuation date (for each claim). E.g. the ValuationNumber for row 5 would be 2, because row 5 describes claim 249 on date 01/30/1980, which is the second time claim 249 was evaluated. The complete output for df
would look like
df
Claim ValuationDate ValuationNumber
1 117 01/05/1965 1
2 249 01/05/1980 1
3 117 01/10/1965 2
4 117 01/20/1965 3
5 249 01/30/1980 2
6 652 01/10/1990 1
What's an efficient way to add the column I need?