I have some data that looks like this:
Value <- c(-0.07, -0.07, -0.0003, 0.45, 0.45, 1.2, 1.4, 1.4, 1.4)
I need to convert it to "ranked" data but I would like all ties to be given the same value AND the rankings to be sequential, such that:
# new.value
1 1 2 3 3 4 5 5 5
I've tried the rank() function in R but I'm having trouble with the ties.
You can turn the ranks into a factor, and then convert the factor into integers. Consider:
rank(Value)
# [1] 1.5 1.5 3.0 4.5 4.5 6.0 8.0 8.0 8.0
as.numeric(factor(rank(Value)))
# [1] 1 1 2 3 3 4 5 5 5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With