开发者

assign integer order to decimal numbers

开发者 https://www.devze.com 2023-03-27 03:16 出处:网络
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 fun

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!!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消