On Jan 4, 2012, at 8:46 PM, David Winsemius wrote:


On Jan 4, 2012, at 7:43 PM, Robert Baer wrote:

-----Original Message----- From: lynn.tsai
Sent: Wednesday, January 04, 2012 3:38 PM
To: r-help@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.

It means the author either doesn't know the 'sample' function, or wants you to understand how to use 'rbinom', or that's just the way she thinks.

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]

C.f.

X1<-sample( c("A","B"), n,  prob= c(0.6, 0.4))
X2<-sample( c("C","D"), n,  prob= c(0.6 ,0.4))


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.

Sorry for the blank message.
--

David Winsemius, MD
West Hartford, CT

______________________________________________
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.

Reply via email to