[R] sample() question
R Newbie
help0938450 at gmail.com
Thu Aug 19 02:12:12 CEST 2010
Just to clarify some of your language here before some others rip you apart, you mean to say you'd like to take a random sample of size 5 and not 5 random samples.
Now, I believe you can control the probability with which each element of your original data set is sampled (using weights), but in order to obtain a random sample such that all values are included, then you must write the code and keep sampling until all elements appear, but your random sample size may be larger than size 5.
On Aug 18, 2010, at 4:58 PM, Chen,Shaofei wrote:
Hello all,
I have a question regarding sample() in R. For example, I have a set:
set <- c(2,3,5)
and I want to draw 5 samples from this set, so replacement is true:
m <- sample(set, 5, replace=TRUE)
However here comes a problem, for example, I will have (2,3,3,2,5), but I
will also get (3,3,5,5,3) in some cases. This means element 2 has not been
sampled in this case.
The way I want to do is to random sample with replacement, but all elements
have to be sampled.
Any solutions?
Thanks!
Regards,
Shaofei
[[alternative HTML version deleted]]
______________________________________________
R-help at 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.
More information about the R-help
mailing list