[R] replace id by running number
Henrique Dallazuanna
wwwhsd at gmail.com
Sat Mar 27 17:34:53 CET 2010
Try this:
as.numeric(factor(y, levels = unique(y)))
On Sat, Mar 27, 2010 at 12:42 PM, sun <sun.sonny71 at googlemail.com> 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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list