[R] Sampling given a table of percentages?

Liaw, Andy andy_liaw at merck.com
Wed Feb 16 20:00:14 CET 2005


Wouldn't sample(length(V), prob=V) do?

Andy

> From: Ben Hyde
> 
> I have a vector V.  sum(V) = 100, i.e. it's percentages.  
> length(V) is 
> large.  I wish to generate samples (with replacement is fine), 
> integers, in the range 1:length(V) who's distribution is 
> driven by the 
> distribution implied by the percentages in V.    V is unsorted, but 
> that could change.  I'd rather not be too specific about the 
> distribution of V.    I can certainly solve the problem 
> intersecting my 
> thin knowledge of R with my skills in programming, but I suspect this 
> is trivial to somebody fluent in R.   Suggestions?  Thanks!  - ben
> 
> ----
> http://enthusiasm.cozy.org/   -- blog
> tel:+1-781-240-2221  -- mobile, et.al.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list