On Tuesday 24 March 2009, you 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!).

Actually, no.
You are sampling from a vector, and where you're using the sampled values (on 
the rows or on the variables) is up to you.

Let's say we have a dataset with 100 cases and 10 variables:

Case 1:
mydata.sub <- mydata[ , sample(10, 7)]

This will sample 7 variables out of 10.

Case 2:
mydata.sub <- mydata[sample(100, 10), ]

This will sample 10 cases out of 100.

> 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.

I think you need to read the help for:
?"["

and most probably one of the introductory books for R.
I hope this helps,
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
     +40 21 3120210 / int.101
Fax: +40 21 3158391


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to