I have a data frame with repeating IDs and different values, what I want to do is rank each value within it respective ID
test <- data.frame(ID = c("A", "B", "C","A", "B", "C","A", "B", "C"), Value = c(15,1,5,17,3,1,19,2,2))
ID Value
1 A 15
2 B 1
3 C 5
4 A 17
5 B 3
6 C 1
7 A 19
8 B 2
9 C 2
I can sort them but I can't figure out how to assign the rank values.
test[order(test$ID, test$Value, decreasing = T),]
ID Value
3 C 5
9 C 2
6 C 1
5 B 3
8 B 2
2 B 1
7 A 19
4 A 17
1 A 15
Desired output would be
ID Value Rank
3 C 5 1
9 C 2 2
6 C 1 3
5 B 3 1
8 B 2 2
2 B 1 3
7 A 19 1
4 A 17 2
1 A 15 3