[R] sample()

Thomas Lumley tlumley at u.washington.edu
Thu Aug 2 18:07:48 CEST 2001


On Thu, 2 Aug 2001, Christof Bigler wrote:

> Dear R users,
>
> is there a way to extract directly rows instead of column vectors
> using the function sample()?
> I have already tried to transpose and back-transpose my dataframe,
> but I couldn't manage to get rid off the levels in the resulting
> dataframe.
>

Sample from 1:n (or from the row names) and use this as an index to the
dataframe

eg
data(trees)
index<-seq(length=NROW(trees))
trees[sample(index,10),]

or
library(MASS)
data(hills)
hills[sample(rownames(hills),10),]


	-thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list