Re: [R] else if statement error

2009-10-06 Thread Gabor Grothendieck
2009/10/6 Uwe Ligges : > > > Gabor Grothendieck wrote: >> >> 2009/10/6 Uwe Ligges : >>> >>> The first rule is easy: As long as you are using scalar valued (i.e. >>> length >>> 1 vectors in R) "cond", you should prefer >>>  if(cond) cons.expr  else  alt.expr >>> rather than >>>  ifelse(cond, yes, no

Re: [R] else if statement error

2009-10-06 Thread Uwe Ligges
Gabor Grothendieck wrote: 2009/10/6 Uwe Ligges : The first rule is easy: As long as you are using scalar valued (i.e. length 1 vectors in R) "cond", you should prefer if(cond) cons.expr else alt.expr rather than ifelse(cond, yes, no) because the latter one evaluates both "yes" and "no" whi

Re: [R] else if statement error

2009-10-06 Thread Gabor Grothendieck
2009/10/6 Uwe Ligges : > > The first rule is easy: As long as you are using scalar valued (i.e. length > 1 vectors in R) "cond", you should prefer >  if(cond) cons.expr  else  alt.expr > rather than >  ifelse(cond, yes, no) > because the latter one evaluates both "yes" and "no" while the former one

Re: [R] else if statement error

2009-10-06 Thread Uwe Ligges
David Winsemius wrote: On Oct 5, 2009, at 5:38 AM, Martin Maechler wrote: "DW" == David Winsemius on Sat, 3 Oct 2009 12:56:51 -0400 writes: DW> On Oct 3, 2009, at 11:54 AM, Chen Gu wrote: Hello, I am doing a simple if else statement in R. But it always comes out error such as 'un

Re: [R] else if statement error

2009-10-05 Thread David Winsemius
On Oct 5, 2009, at 5:38 AM, Martin Maechler wrote: "DW" == David Winsemius on Sat, 3 Oct 2009 12:56:51 -0400 writes: DW> On Oct 3, 2009, at 11:54 AM, Chen Gu wrote: Hello, I am doing a simple if else statement in R. But it always comes out error such as 'unexpected error' There are

Re: [R] else if statement error

2009-10-05 Thread Martin Maechler
> "DW" == David Winsemius > on Sat, 3 Oct 2009 12:56:51 -0400 writes: DW> On Oct 3, 2009, at 11:54 AM, Chen Gu wrote: >> Hello, >> >> I am doing a simple if else statement in R. But it always comes out >> error >> such as 'unexpected error' >> There are

Re: [R] else if statement error

2009-10-03 Thread Duncan Murdoch
On 03/10/2009 11:54 AM, Chen Gu wrote: Hello, I am doing a simple if else statement in R. But it always comes out error such as 'unexpected error' There are two variables. ini and b. when ini=1, a=3; when ini>1 and b>2, a=5; all other situations, a=6. I don't know where it is wrong. Here is my c

Re: [R] else if statement error

2009-10-03 Thread David Winsemius
On Oct 3, 2009, at 11:54 AM, Chen Gu wrote: Hello, I am doing a simple if else statement in R. But it always comes out error such as 'unexpected error' There are two variables. ini and b. when ini=1, a=3; when ini>1 and b>2, a=5; all other situations, a=6. I don't know where it is wrong.

Re: [R] else if statement error

2009-10-03 Thread Benilton Carvalho
align the 'else if' and 'else' with the closing curly brackets. if (condA){ doStuff() } else if (condB){ doOtherStuff() } else { doWhatever() } b On Oct 3, 2009, at 12:54 PM, Chen Gu wrote: Hello, I am doing a simple if else statement in R. But it always comes out error such as 'une

[R] else if statement error

2009-10-03 Thread Chen Gu
Hello, I am doing a simple if else statement in R. But it always comes out error such as 'unexpected error' There are two variables. ini and b. when ini=1, a=3; when ini>1 and b>2, a=5; all other situations, a=6. I don't know where it is wrong. Here is my code ini=3 b=4 if (ini==1) { a=3