order - Sequentially reorganize a vector in R -


i have numeric element z below:

> sort(z)   [1]  1  5  5  5  6  6  7  7  7  7  7  9  9 

i sequentially reorganize element have

> z   [1]  1  2  2  2  3  3  4  4  4  4  4  5  5   

i guess converting z factor , use index should way.

you answered really:

as.integer(factor(sort(z))) 

i know has been accepted decided inside factor() see how it's done there. more or less comes down this:

x <- sort(z) match(x, unique(x)) 

which line suppose should faster if matters.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -