A direct answer to your question: On Wed, Jan 4, 2012 at 4:38 PM, lynn.tsai <vernal....@gmail.com> wrote: > 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]
Is that the "+1" is adding 1 to the result returned from rbinom(). Look at what happens when you do: R> c(1, 3, 5, 10) + 1 ¡Tada! If you're just learning R, you'll find it useful to deconstruct "complex" commands into their "unit" pieces, if you catch my meaning ... look at what rbinom() returns, look at what it returns when you "+1" it, then look at what you get when you use that whole expression inside the "[]" to select elements in `c("A", "B")` You will see the light ... HTH, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact ______________________________________________ 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.