[R] a quick question about "rbinom"
David Winsemius
dwinsemius at comcast.net
Thu Jan 5 05:05:24 CET 2012
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 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.
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
More information about the R-help
mailing list