yes but add 'replace=TRUE' into that statement to sample with replacement.
On Wed, 2005-02-16 at 14:00 -0500, Liaw, Andy wrote: > 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@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 > > > > > > ______________________________________________ > R-help@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 > ______________________________________________ R-help@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