[R] sampling from data.frame

axionator axionator at gmail.com
Wed Dec 3 00:27:16 CET 2008


Hi all,
I have a data frame with "clustered" rows as follows:
Cu1  x1 y1 z1 ...
Cu1  x2 y2 z2 ...
Cu1  x3 y3 z3 ... # end of first cluster Cu1
Cu2  x4 y4 z4 ...
Cu2  x5 y5 z5
Cu2  ...               # end of second cluster Cu2
Cu3 ...
...
"cluster"-size is 3 in the example above (rows making up a cluster are
always consecutive). Is there any faster way to sample n clusters
(with replacement) from this dataframe and build up a new data frame
out of these sampled clusters? I use the "sample" function and a
for-loop.

Thanks in advance
Armin



More information about the R-help mailing list