Skip to content
Prev 30265 / 398506 Next

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:

            
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)),]


--