Re: [R] Obtaining replicates numbers of a vector

From: jim holtman <jholtman_at_gmail.com>
Date: Wed, 19 Dec 2007 08:06:06 -0500

Here is another way of doing it:

> x <- c('A','B','A','C','C','B')
> ave(rep(1, length(x)), x, FUN=cumsum)
[1] 1 1 2 1 2 2
>

On Dec 19, 2007 5:36 AM, Eric Lecoutre <ericlecoutre_at_gmail.com> wrote:
> Dear R-help,
>
> I am trying to have a generic way to assess the replicates in a character
> vector.
> Say that I have the following vector:
>
> x <- c('A','B','A','C','C','B')
>
> I would like to obtain:
>
> replicates <- c(1,1,2,1,2,2)
>
> each number beeing the time we see the corresponding value in x.
>
> Any clever and generic way to obtain that?
>
> Eric
>
>
>
>
> --
> Eric Lecoutre
> Consultant - Business & Decision
> Business Intelligence & Customer Intelligence
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 19 Dec 2007 - 13:09:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 19 Dec 2007 - 14:00:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.