sample with equal probabilities

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

sample with equal probabilities

solafah bh
Hello
If I have this vector x=c(5,1,2,9) and n=length(x) and I want to sample one value from x , and each value of x has equal probability to appear (1/n).
Are the following codes equivalent??
sample(x,1,replace=TRUE)  and   sample(x,1,replace=TRUE,prob=rep(1/n , n))
 
Regards
        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: sample with equal probabilities

Michael Weylandt
Please don't double post.

And see my response to you here:
https://stat.ethz.ch/pipermail/r-help/2012-October/325470.html

Michael

On Sat, Oct 6, 2012 at 6:51 PM, solafah bh <[hidden email]> wrote:

> Hello
> If I have this vector x=c(5,1,2,9) and n=length(x) and I want to sample one value from x , and each value of x has equal probability to appear (1/n).
> Are the following codes equivalent??
> sample(x,1,replace=TRUE)  and   sample(x,1,replace=TRUE,prob=rep(1/n , n))
>
> Regards
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.