Re: [R] ? about sample

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

From: Peter Dalgaard BSA (p.dalgaard@biostat.ku.dk)
Date: Fri 08 Mar 2002 - 23:44:27 EST


Message-id: <x2elivns9g.fsf@blueberry.kubism.ku.dk>


"jimi adams" <imij@columbus.rr.com> writes:

> 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
> while this is not exactly what i am using it for, i need the capabilities to
> deal with zeros (as the probability valuees that i will be using wil vary,
> and sometimes will include zeros), and this seems like the zero's are the
> problem...
>
> currently i am assigning zero values in my initial probability vector to a
> miniscule value(1E-4)
>
> is there a more efficient way to deal with this, or another command that
> does a similar thing to only select a single element, where as sample orders
> the entire set according to the prob?

sample (1:4, size=1, prob=c(0,0,1,0))
             ======

The default is size=4 and subsetting the result doesn't change that.
Notice that this is sampling without replacement, so what is the
algorithm supposed to do when the first element has been sampled?

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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