John Sorkin
2008-Sep-20 19:43 UTC
[R] selecting from a series of integers with pre-determined probabilities
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 th...{{dropped:6}}
jim holtman
2008-Sep-20 20:12 UTC
[R] selecting from a series of integers with pre-determined probabilities
?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 <jsorkin@grecc.umaryland.edu>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}}
Bert Gunter
2008-Sep-21 22:33 UTC
[R] selecting from a series of integers withpre-determined probabilities
?sample. -- Bert Gunter -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of John Sorkin Sent: Saturday, September 20, 2008 12:43 PM To: r-help at r-project.org Subject: [R] selecting from a series of integers withpre-determined probabilities 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 th...{{dropped:8}}