[R] Odp: If Else Function

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Tue, 11 Dec 2007 13:47:02 +0100


Hi

r-help-bounces_at_r-project.org napsal dne 11.12.2007 13:06:14:

>
> Hello everyone,
>
> I would like to use the "if" statements and I was thinking sth like
>
> If () {} else{ if() {} else{} }
>
> Is this a possible solution and is there any syntax error?

Except the first letter, nothing sooms to be wrong.

> if (1==1) {print("a")} else { if(1==1) {print("b")} else{print("c")} }
[1] "a"
> if (1==2) {print("a")} else { if(1==1) {print("b")} else{print("c")} }
[1] "b"
> if (1==2) {print("a")} else { if(1==2) {print("b")} else{print("c")} }
[1] "c"
>

I beleive you noticed a difference between if() and ifelse() functions. And of course if you spread your command in several rows be carefull not to have valid syntax before you ended a whole command. e.g.
if (1==2) {print("a")}
else { if(1==2) {print("b")} else{print("c")} }

Error: unexpected 'else' in "else"

Regards
Petr

>
> Could anyone give me some advice? Many thanks.
> --
> View this message in context: http://www.nabble.com/If-Else-Function-
> tp14272459p14272459.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.



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. Received on Tue 11 Dec 2007 - 12:55:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 11 Dec 2007 - 17:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.