RE: [R] Array Manipulation

2005-01-27 Thread Liaw, Andy
Something like:

dat[dat$ID %in% sample(unique(dat$ID), 3), ]

Andy

 From: [EMAIL PROTECTED]
 
 I have a data set that looks like the following:
 ID  Responce
 1   57
 1   63
 1   49
 2   31
 2   45
 2   67
 2   91
 3   56
 3   43
 4   23
 4   51
 4   61
 4   76
 4   68
 5   34
 5   35
 5   45
 I used sample(unique(ID)) to select a sample if ID's, say, 
 (1,4,5).  Now
 I want to pull out the rows with ID's 1, 4, and 5.  I've 
 tried forceing
 the matrix into a vector but it does not create and 
 appropriate vector.
  I've also tried the if statment but it didn't work right either.  Any
 suggestions?
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Array Manipulation

2005-01-27 Thread Douglas Bates
Liaw, Andy wrote:
Something like:
dat[dat$ID %in% sample(unique(dat$ID), 3), ]
or
subset(dat, ID %in% sample(unique(ID), 3))
which I find to be more readable.
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Array Manipulation

2005-01-27 Thread Eric Rodriguez
and something like that:

dat[dat$ID == sample(unique(dat$ID), 3), 2]   ?

I'm not sure about the ,2 maybe you need the full matrix ?


ps: first time, i forgot the list

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html