Hello I am trying to resample from this data set (see below). The function I am using so far is doing it by considering A and B columns as linked. I used this function.>NUCh_rep<-replicate(500,data[sample(1:nrow(data),replace=T),],simplify=F)What I need is to resample (500 times) with replacement but considering A and B columns UNLINKED. Any advice it is most appreciated. Thanks. A B 5 257 259 10 257 259 10.1 257 259 4 257 259 9 257 259 2 257 259 8 257 259 1 257 259 8.1 257 259 8.2 257 259 7 255 257 [[alternative HTML version deleted]]
Hi> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Rosario Garcia Gil > Sent: Wednesday, September 11, 2013 12:21 PM > To: r-help at r-project.org > Subject: [R] resample from data frame: unlinked columns > > Hello > > I am trying to resample from this data set (see below). The function I > am using so far is doing it by considering A and B columns as linked. I > used this function. > > >NUCh_rep<- > replicate(500,data[sample(1:nrow(data),replace=T),],simplify=F)Sample rows 1000 times and use two parts of this index ind<-sample(1:nrow(data), 1000, replace=TRUE) data[ind[1:500], "A"] data[ind[501:1000], "B"] You can organize it to data frame or matrix e.g. result <- cbind(data[ind[1:500], "A"], data[ind[501:1000], "B"]) Regards Petr> > What I need is to resample (500 times) with replacement but considering > A and B columns UNLINKED. Any advice it is most appreciated. Thanks. > > A B > 5 257 259 > 10 257 259 > 10.1 257 259 > 4 257 259 > 9 257 259 > 2 257 259 > 8 257 259 > 1 257 259 > 8.1 257 259 > 8.2 257 259 > 7 255 257 > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.
Hi, Using ur code: dat1<- read.table(text="A????????? B 5????????? 257????? 259 10??????? 257????? 259 10.1????? 257????? 259 4????????? 257????? 259 9????????? 257????? 259 2????????? 257????? 259 8????????? 257????? 259 1????????? 257????? 259 8.1??????? 257????? 259 8.2??????? 257????? 259 7????????? 255????? 257",sep="",header=TRUE) set.seed(49) ?res<-sapply(dat1,function(x) as.vector(replicate(500,x[sample(seq_along(x),length(x),replace=TRUE)]))) ?dim(res) #[1] 5500??? 2 A.K. ----- Original Message ----- From: Rosario Garcia Gil <M.Rosario.Garcia at slu.se> To: "r-help at r-project.org" <r-help at r-project.org> Cc: Sent: Wednesday, September 11, 2013 6:20 AM Subject: [R] resample from data frame: unlinked columns Hello I am trying to resample from this data set (see below). The function I am using so far is doing it by considering A and B columns as linked. I used this function.>NUCh_rep<-replicate(500,data[sample(1:nrow(data),replace=T),],simplify=F)What I need is to resample (500 times) with replacement but considering A and B columns UNLINKED. Any advice it is most appreciated. Thanks. ? ? ? ? ? ? A? ? ? ? ? B 5? ? ? ? ? 257? ? ? 259 10? ? ? ? 257? ? ? 259 10.1? ? ? 257? ? ? 259 4? ? ? ? ? 257? ? ? 259 9? ? ? ? ? 257? ? ? 259 2? ? ? ? ? 257? ? ? 259 8? ? ? ? ? 257? ? ? 259 1? ? ? ? ? 257? ? ? 259 8.1? ? ? ? 257? ? ? 259 8.2? ? ? ? 257? ? ? 259 7? ? ? ? ? 255? ? ? 257 ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.