[R] Array Manipulation

Liaw, Andy andy_liaw at merck.com
Thu Jan 27 20:37:02 CET 2005


Something like:

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

Andy

> From: cdsmith at ksu.edu
> 
> 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 at 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
> 
>




More information about the R-help mailing list