?sample efficient enough?> system.time(z <- sample(1:5, 500000, TRUE, prob=c(.05,.05,.05,.05,.8))) user system elapsed 0.12 0.02 0.14 > table(z) z 1 2 3 4 5 24800 24771 25039 25022 400368 >
On Sat, Sep 20, 2008 at 3:43 PM, John Sorkin <[EMAIL PROTECTED]>wrote: > R 2.6 > Windows XP > > I need to select from the integers 1,2,3,4,5 with some pre-determined > probability, e.g. probability of selecting 5 80%, probability of selecting 1 > or 2 or 3 or 4 20%. Any suggestions for how I might accomplish this? I > need to do it very efficiently as I will be doing it 500,000 times. > Thanks > John > > John David Sorkin M.D., Ph.D. > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing) > > Confidentiality Statement: > This email message, including any attachments, is for ...{{dropped:22}} ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.