Rescale Vector R

后端 未结 2 1761
走了就别回头了
走了就别回头了 2021-01-19 08:21

Suppose I have a vector of integers such as:

> x
[1]  1  1  1  4  4 13 13 14

I am looking for an efficient way in R to rescale the vecto

2条回答
  •  有刺的猬
    2021-01-19 08:59

    Try the following command, assuming that v is your vector

    rank( v )
    

    see ?rank for more information.

    Well, this does give another result, but is correct as ranking, which is what I thought you want to achieve. To get your preferred result, do

    as.integer( factor( v ) )
    

提交回复
热议问题