When I create bootstrap samples from a data frame datta
using the following codes
boot1a <- replicate(3, do.call("rbind", lapply(sample(unique(datta$pid),2000,replace=TRUE), function(x) datta[datta$pid==x,])), simplify=FALSE)
boot1b <- data.frame(boot1a) # data frame from the list
sample1 <- boot1b[order(boot1b$pid),] # sorting based on pid and storing
variables in the bootstrap sample sample1
have names ending with .1, .2, .3, ...
. (pid
is person ID, it takes similar values for different observations of the same person). For instance, with the above code a variable xy
in datta
will have names xy
, xy.1
, and xy.2
associated with the first, the second and the third bootstrap samples. I would rather prefer to have different bootstrap samples named differently with the variable names in each remaining the same as those in the original data frame. In the above case, what I would like to have would be bootstrap samples stored in three different data frames, say, boot1, boot2, boot3
, where variable names in each data frame is the same as that in the original data frame. I began doing it manually with one replication at a time, but it is gonna take a lot of time to create many bootstrap samples. Does somebody has any suggestion on how to do this in a better way?
EDIT
The first few observations for four of the many variables in the data frame datt
is as follows.
pid xy zy wy
1 10 2 -5
1 12 3 -4.5
1 14 4 -4
1 16 5 -3.5
1 18 6 -3
1 20 7 -2.5
2 22 8 -2
2 24 9 -1.5
2 26 10 -1
2 28 11 -0.5
2 30 12 0
2 32 13 0.5