Re: [R] ? about sample

About this list Date view Thread view Subject view Author view Attachment view

From: Thomas Lumley (tlumley@u.washington.edu)
Date: Sat 09 Mar 2002 - 04:05:16 EST


Message-id: <Pine.A41.4.44.0203080902560.69958-100000@homer34.u.washington.edu>

On Fri, 8 Mar 2002, jimi adams wrote:

> i am trying to use the
> sample command and have one question about it:
> i am getting the error
>
> Error in sample(length(x), size, replace, prob) :
> insufficient positive probabilities
>
> when i use something like:
> sample (1:4, prob=c(0,0,1,0))[1]
>
> i was expecting that to return a 3 every time

It sounds like you want to add replace=TRUE, eg

R> sample(1:4,prob=c(0,0,1,0),replace=TRUE)
[1] 3 3 3 3

You were trying to sample four numbers without replacement from a set
effectively containing only one number. That's what the error message
means.

        -thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Wed 16 Oct 2002 - 11:56:58 EST