[R] Creating vectors

Michael Bedward michael.bedward at gmail.com
Thu Aug 12 04:54:51 CEST 2010


Here's another way...

x <- c(2,2,4,6,2,4,4,6,8,6)
match(x, unique(x))

Produces...
[1] 1 1 2 3 1 2 2 3 4 3


On 12 August 2010 01:48, clips10 <m.mcquillan at lancaster.ac.uk> wrote:
>
> I didn't really know what to post as the topic subject, but I have a vector,
> for instance (2,2,4,6,2,4,4,6,8,6) and I want to create another vector which
> is just numbers from 1 to 4 since there are only 4 unique numbers in my
> vector, so for instance 2 would be 1, 4 would be 2, 6 would be 3, and 8
> would be 4, so my new vector would be



More information about the R-help mailing list