Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assign integer order to decimal numbers

Tags:

integer

r

I have 200 numbers all between 0 and 1. I would like to rank them and assign integer values 1-199. It could be something very easy to accomplish but i don't know which function to use - the order function does not really work.

say here is what I have:

    0.12, 0.56, 0.112, 0.8, 0.356, 0.00001

I want:

    3, 5, 2, 6, 4, 1

Thank you!!

like image 552
vanilli Avatar asked Aug 08 '11 23:08

vanilli


1 Answers

There is a built in function for exactly this purpose:

x <- runif(10)
rank(x)
[1]  7  3  8 10  4  2  5  1  6  9

see ?rank for the options for dealing with ties.

like image 141
joran Avatar answered Sep 28 '22 09:09

joran