Sampling from a Data Frame
On Sat, 5 Apr 2003 09:01:13 +1200 (NZST), Ko-Kang Kevin Wang
<kwan022 at stat.auckland.ac.nz> wrote:
Hi, I've been looking through the documentation for sample(), but can only get it to work with vectors. Is it possible to sample from a dataframe?
I think somebody already answer, but, just in case: suppose dfrme is a "data frame" and "n" is the sample size, then using indexing you try this: samp1<-dfrme[sample(1:dim(dfrme)[1],n),] If you want to preserve the original order in the sample: samp1<-dfrme[sort(sample(1:dim(dfrme)[1],n)),] --