Skip to content
Prev 308580 / 398506 Next

Help me please to code....

Hello,

First of all, you should _really_ try to read An Introduction to R, file 
R-intro.pdf that comes with every installation of R. The answer to your 
question is in chapter 9 Grouping, loops and conditional execution.
It's the very first example:

"9.2.1 Conditional execution: if statements
The language has available a conditional construction of the form
 > if (expr_1) expr_2 else expr_3
where expr 1 must evaluate to a single logical value and the result of 
the entire expression is
then evident."

Note the "evident" bit.


if(X == 0) Y <- 5/2 else Y <- 7

or, when you become more familiar with R,

Y <- if(X == 0) 5/2 else 7

But do read the manual.
Hope this helps,

Rui Barradas

Em 21-10-2012 20:03, Rlotus escreveu: