[R] else if statement error

Benilton Carvalho bcarvalh at jhsph.edu
Sat Oct 3 18:55:06 CEST 2009


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 '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
>     }
>    else if (ini>1 and b>2 ) {
>   a=5
>    }
>   else {a=6}
>
>
> Thanks a lot.
> --
> Best,
> Chen
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.




More information about the R-help mailing list