[R] a quick question about "rbinom"

Robert Baer rbaer at atsu.edu
Thu Jan 5 01:43:44 CET 2012


-----Original Message----- 
From: lynn.tsai
Sent: Wednesday, January 04, 2012 3:38 PM
To: r-help at r-project.org
Subject: [R] a quick question about "rbinom"

Hello, I have the following code using rbinom, but I don't understand what
*"+1"* means in the code. Could someone help? Thanks so much,

> X1<-c("A","B")[rbinom(n,1,0.6)+1]
> X2<-c("C","D")[rbinom(n,1,0.1)+1]

It mean index the vector as 1's and 2's  (1st and 2nd item in list) rather 
than 0's and 1's because R indices start at 1, not 0.

------------------------------------------
Robert W. Baer, Ph.D.
Professor of Physiology
Kirksville College of Osteopathic Medicine
A. T. Still University of Health Sciences
800 W. Jefferson St.
Kirksville, MO 63501
660-626-2322
FAX 660-626-2965



More information about the R-help mailing list