hi, I would like to subsample the array c(1:200) at random into ten subsamples v1,v2,...,v10. I tried with to go progressively like this:> x<-c(1:200) > v1<-sample(x,20) > y<-x[-v1] > v2<-sample(y,20)and then I want to do:>x<-y[-v2]Error: subscript out of bounds.
nicolas.deig at epfl.ch wrote:> hi, > > I would like to subsample the array c(1:200) at random into ten subsamples > v1,v2,...,v10. > > I tried with to go progressively like this: > > > >>x<-c(1:200) >>v1<-sample(x,20) >>y<-x[-v1] >>v2<-sample(y,20) > > > and then I want to do: > > >>x<-y[-v2] > > Error: subscript out of bounds.Let's do a simple example: x <- 1:3 v1 <- sample(x, 1) # assume v1 = 2: y <- x[-v1] # now: y = c(1, 3) v2 <- sample(y,1) # assume v2 = 3, what happens now? x <- y[-v2] Uwe Ligges> ______________________________________________ > 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
nicolas.deig at epfl.ch writes:> hi, > > I would like to subsample the array c(1:200) at random into ten subsamples > v1,v2,...,v10.(Why are you c()'ing a single vector?)> I tried with to go progressively like this: > > > > x<-c(1:200) > > v1<-sample(x,20) > > y<-x[-v1] > > v2<-sample(y,20) > > and then I want to do: > > >x<-y[-v2] > Error: subscript out of bounds.That's not going to work (hint, the values contained in y do not correspond to their indices). I'd just do split(sample(1:200),rep(1:10,each=20)) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
> From: nicolas.deig at epfl.ch > > hi, > > I would like to subsample the array c(1:200) at random into > ten subsamples > v1,v2,...,v10. > > I tried with to go progressively like this: > > > > x<-c(1:200) > > v1<-sample(x,20) > > y<-x[-v1] > > v2<-sample(y,20)This only worked because your original data happens to be the same as the indices (1:200). The next round failed because that's not true any more.> and then I want to do: > > >x<-y[-v2] > Error: subscript out of bounds.Can you explain more explicitly what you mean by subsamples? Here you're trying to overwrite the original data by sampling from the subsample, which doesn't seem like what you said you want. If you simply want to randomly divide 1:200 into 10 sets, try something like: x.sample <- matrix(sample(x), ncol=10) where x.sample is a matrix with 10 columns, each column containing a random (but disjoint) part of x. Andy
nicolas.deig at epfl.ch a ?crit :>hi, > >I would like to subsample the array c(1:200) at random into ten subsamples >v1,v2,...,v10. > >I tried with to go progressively like this: > > > > >>x<-c(1:200) >>v1<-sample(x,20) >>y<-x[-v1] >>v2<-sample(y,20) >> >> > >and then I want to do: > > > >>x<-y[-v2] >> >> >Error: subscript out of bounds. > >__ >You should try : x[-c(v2,v1)] But more accurately, try permutting the all x and choose the 20 firsts entries, the 20 after, ... I think that will do the job x <- 1:200 y <- x[sample(200)] v1 <- y[ 1:20] v2 <- y[21:40] ... Regards. Romain. -- Romain FRANCOIS : francoisromain at free.fr page web : http://addictedtor.free.fr/ (en construction) 06 18 39 14 69 / 01 46 80 65 60 _______________________________________________________ Etudiant en 3eme ann?e Institut de Statistique de l'Universit? de Paris (ISUP) Fili?re Industrie et Services http://www.isup.cicrp.jussieu.fr/
Consider using a list. This will create a list with 10 entries of your 20 samples: x <- 1:200 myList <- split(x, cut(sample(x,200),breaks=10)) __________________________________________________________ James Holtman "What is the problem you are trying to solve?" Executive Technical Consultant -- Office of Technology, Convergys james.holtman at convergys.com +1 (513) 723-2929 nicolas.deig at epfl.ch Sent by: To: r-help at stat.math.ethz.ch r-help-bounces at stat.m cc: ath.ethz.ch Subject: [R] subsampling 01/14/2005 11:23 hi, I would like to subsample the array c(1:200) at random into ten subsamples v1,v2,...,v10. I tried with to go progressively like this:> x<-c(1:200) > v1<-sample(x,20) > y<-x[-v1] > v2<-sample(y,20)and then I want to do:>x<-y[-v2]Error: subscript out of bounds. ______________________________________________ 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