[R] sample function

Marc Schwartz MSchwartz at MedAnalytics.com
Fri Mar 11 04:20:15 CET 2005


On Thu, 2005-03-10 at 20:54 -0600, mirage sell wrote:
> Hi everyone, I need help.
> I want to have a "uniform" kind distribution. When I used sample function I 
> got almost twice many zeros compared to other numbers. What's wrong with my 
> command ?
> 
> temp <-sample(0:12, 2000, replace=T,prob=(rep(1/13,13)))
> hist(temp)
> 
> Thanks in advance,

Hint: take note that there are only 12 cells in the plot, not 13...

However, note that the frequency of the 13 elements are appropriate:

> table(sample(0:12, 2000, replace=T))

  0   1   2   3   4   5   6   7   8   9  10  11  12
158 156 151 163 156 158 146 154 134 158 146 147 173


Review the details of how the breaks are selected in ?hist.

BTW, you do not need to specify the 'prob' argument if you want equal
probabilities as per my example above.

HTH,

Marc Schwartz




More information about the R-help mailing list