[R] random samples

Philipp Pagel p.pagel at gsf.de
Thu Jan 13 15:05:05 CET 2005


On Thu, Jan 13, 2005 at 01:50:38PM +0100, nicolas.deig at epfl.ch wrote:

> I need to divide the array
> 
> > A<-c(1:200)
> 
>  into two subsets at random. Therefore I use the function "sample" in R:

I suggest a slightly different approach which is probably faster than
using setdif() or %in% and friends:

a <- 1:200
i <- sample(1:200, 100)
s1 <- a[i]
s2 <- a[-i]

cu
	Philipp
	
-- 
Dr. Philipp Pagel                            Tel.  +49-89-3187-3675
Institute for Bioinformatics / MIPS          Fax.  +49-89-3187-3585
GSF - National Research Center for Environment and Health
Ingolstaedter Landstrasse 1
85764 Neuherberg, Germany
http://mips.gsf.de/staff/pagel




More information about the R-help mailing list