[R] resample from data frame: unlinked columns

arun smartpink111 at yahoo.com
Wed Sep 11 15:04:31 CEST 2013


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.




More information about the R-help mailing list