Message-ID: <4BAE35F0.4010702@erasmusmc.nl>
Date: 2010-03-27T16:44:32Z
From: Dimitris Rizopoulos
Subject: replace id by running number
In-Reply-To: <4bae2752.0f67f10a.018d.6ac4@mx.google.com>
try this:
y <- c(4,4,4,2,45,12,12)
match(y, unique(y))
I hope it helps.
Best,
Dimitris
On 3/27/2010 4:42 PM, sun wrote:
> Dear all,
>
> I want to replace an (unsorted) id variable in a large dataset by a running
> number without changing the order of the cases.
>
> E.g.,
>
> y<- c(4,4,4,2,45,12,12)
>
> should be replaced by something like
>
> x<- c(1,1,1,2,3,4,4)
>
> Sorry for this simple question& thank you very much for your help!
>
>
>
>
>
>
> [[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.
>
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014