Skip to content

Obtaining replicates numbers of a vector

5 messages · Eric Lecoutre, Henrique Dallazuanna, jim holtman +1 more

#
Try this:

replicate <- vector("numeric", len=length(x))
replicate[order(x)] <- unlist(sapply(rle(sort(x))$lengths, seq_len))
On 19/12/2007, Eric Lecoutre <ericlecoutre at gmail.com> wrote:

  
    
#
Here is another way of doing it:
[1] 1 1 2 1 2 2

        
On Dec 19, 2007 5:36 AM, Eric Lecoutre <ericlecoutre at gmail.com> wrote:

  
    
#
You could do:
[1] "A" "B" "A" "C" "C" "B"
[1] 1 1 2 1 2 2

        
--- Eric Lecoutre <ericlecoutre at gmail.com> wrote: