Skip to content

Random sampling based on the observations

4 messages · Adrian Dusa, Uwe Ligges, Arup

#
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.
#
Arup wrote:
mydata[sample(nrow(mydata), 7),]

Uwe Ligges
#
Thank you Adrian. Its working.Thank you so much. Take care =^D=)

Cheers

Arup Pramanik
Business Analyst
Redwood Associates
Bangalore,India.
Adrian Dusa wrote: