[R] resample from data frame: unlinked columns

PIKAL Petr petr.pikal at precheza.cz
Wed Sep 11 14:33:35 CEST 2013


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.



More information about the R-help mailing list