In RStudio, I want to create a rank variable:
The code is as follows:
test <- data.frame(column1 = c(5,5,5,6,6,7,7,7,8))
test$rank <- rank(test)
test
column1 rank
1 5 2.0
2 5 2.0
3 5 2.0
4 6 4.5
5 6 4.5
6 7 7.0
7 7 7.0
8 7 7.0
9 8 9.0
My desired answer is: 1,1,1,2,2,3,3,3,4.