[R] Sampling from a Data Frame

Chuck Cleland ccleland at optonline.net
Fri Apr 4 22:24:06 CEST 2003


Ko-Kang Kevin Wang wrote:
> 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?

Do you want to sample rows from a single dataframe?  How about 
something like this where 10 is the number of rows sampled:

mydata[sample(dim(mydata)[1], 10),]

hope it helps,

Chuck Cleland



More information about the R-help mailing list