[R] how to give the index with some given index ?

David Winsemius dwinsemius at comcast.net
Thu Jan 21 13:38:38 CET 2010


On Jan 21, 2010, at 1:18 AM, Carrie Li wrote:

> Dear R-helpers,
> I have a question about giving index.
> Suppose that I have a vector say, id=1:5, and each of them have some  
> given
> index but some of them may share the same index
> Now, I have another vector, and I want to give it a index based what  
> just
> defined.
>
> # 5 subjects
> test1=1:5
> # corresponding index, so here, subject 2 and subject 4 share the  
> common
> index "1"
> index=c(3,1,2,1,4)
>
> # now I have another vector, and I want to use the index defined above
> test2=c(5,4,2,1,1,5,3)
>
> ## so, the result  should be something like this--index of test2 is
> (4,1,1,3,3,4,2)


 > index[test2]
[1] 4 1 1 3 3 4 2
>
-- 

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list