Re: [R] select subset based on another variable

2010-05-13 Thread David Winsemius
On May 13, 2010, at 9:55 AM, David Winsemius wrote: On May 13, 2010, at 9:48 AM, Carrie Li wrote: Hi, dear R-helpers, I have a simple question regarding selecting subset of a variable based on another variable. Here is the example: xx=rnorm(10) id=sample(1:10, 10) temp=c(6, 1, 8, 2) N

Re: [R] select subset based on another variable

2010-05-13 Thread jim holtman
try this: > xx=rnorm(10) > id=sample(1:10, 10) > > temp=c(6, 1, 8, 2) > xx[match(temp, id)] [1] 0.4874291 -0.6212406 1.5117812 0.5757814 > xx [1] -0.8204684 0.4874291 0.7383247 0.5757814 -0.3053884 1.5117812 0.3898432 -0.6212406 -2.2146999 [10] 1.1249309 > id [1] 5 6 4 2 10 8 9 1

Re: [R] select subset based on another variable

2010-05-13 Thread Henrique Dallazuanna
Try this: subset(xx, id %in% temp) On Thu, May 13, 2010 at 10:48 AM, Carrie Li wrote: > Hi, dear R-helpers, > > I have a simple question regarding selecting subset of a variable based on > another variable. > Here is the example: > > xx=rnorm(10) > id=sample(1:10, 10) > > temp=c(6, 1, 8, 2) >

Re: [R] select subset based on another variable

2010-05-13 Thread David Winsemius
On May 13, 2010, at 9:48 AM, Carrie Li wrote: Hi, dear R-helpers, I have a simple question regarding selecting subset of a variable based on another variable. Here is the example: xx=rnorm(10) id=sample(1:10, 10) temp=c(6, 1, 8, 2) Now, all I want is xx's that their id are 6, 1, 8, 2, in

[R] select subset based on another variable

2010-05-13 Thread Carrie Li
Hi, dear R-helpers, I have a simple question regarding selecting subset of a variable based on another variable. Here is the example: xx=rnorm(10) id=sample(1:10, 10) temp=c(6, 1, 8, 2) Now, all I want is xx's that their id are 6, 1, 8, 2, instead of the position. Any suggestions ? Thank you