[R] Random sampling based on the observations

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Mar 24 14:27:57 CET 2009



Arup wrote:
> Hello!I am having a problem with Random sampling in R. I have used a syntax:
> mydata.sub=sample(mydata,7,replace=FALSE,prob=NULL) which allows me to
> choose a random sample based on the variables(correct me if I am wrong!).
> Suppose I have 10 variable and if I use the above mentioned command then it
> will choose 7 variables out of the 10 randomly. My problem is that I want to
> have a random sample which is not based on the variables but on the values
> of the variables that is the random sample will be based on the
> observations. It will be great if someone can help me out me out with a
> proper syntax. Thanks in Advance.


mydata[sample(nrow(mydata), 7),]

Uwe Ligges




More information about the R-help mailing list