Re: [R] Simple if else statement problem
thanks petr, this is actually shorter ;) Petr Pikal wrote: Hi r-help-boun...@r-project.org napsal dne 13.11.2009 18:54:05: Ok Jim it worked, thank you! it´s funny because it worked with the first syntax in some cases... you can use another approach in this case P-max(c(P1,P2)) Regards Petr anna_l wrote: Hello, I am getting an error with the following code: if( P2 P1) + { + P-P2 + } else Erro: unexpected 'else' in else { + P-P1 + } I checked the syntax so I don´t understand, I have other if else statements with the same syntax working. Thanks in advance -- View this message in context: http://old.nabble.com/Simple-if-else-statement- problem-tp26340336p26340642.html Sent from the R help mailing list archive at Nabble.com. __ 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. __ 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. -- View this message in context: http://old.nabble.com/Simple-if-else-statement-problem-tp26340336p26371185.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Simple if else statement problem
Hi r-help-boun...@r-project.org napsal dne 13.11.2009 18:54:05: Ok Jim it worked, thank you! it´s funny because it worked with the first syntax in some cases... you can use another approach in this case P-max(c(P1,P2)) Regards Petr anna_l wrote: Hello, I am getting an error with the following code: if( P2 P1) + { + P-P2 + } else Erro: unexpected 'else' in else { + P-P1 + } I checked the syntax so I don´t understand, I have other if else statements with the same syntax working. Thanks in advance -- View this message in context: http://old.nabble.com/Simple-if-else-statement- problem-tp26340336p26340642.html Sent from the R help mailing list archive at Nabble.com. __ 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. __ 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.
[R] Simple if else statement problem
Hello, I am getting an error with the following code: if( P2 P1) + { + P-P2 + } else Erro: unexpected 'else' in else { + P-P1 + } I checked the syntax so I don´t understand, I have other if else statements with the same syntax working. Thanks in advance -- View this message in context: http://old.nabble.com/Simple-if-else-statement-problem-tp26340336p26340336.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Simple if else statement problem
align the else with the curly brackets if (yes){ be happy }else{ complain } b On Nov 13, 2009, at 3:33 PM, anna_l wrote: Hello, I am getting an error with the following code: if( P2 P1) + { + P-P2 + } else Erro: unexpected 'else' in else { + P-P1 + } I checked the syntax so I don´t understand, I have other if else statements with the same syntax working. Thanks in advance -- View this message in context: http://old.nabble.com/Simple-if-else-statement-problem-tp26340336p26340336.html Sent from the R help mailing list archive at Nabble.com. __ 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. __ 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.
Re: [R] Simple if else statement problem
Anna, I think the else needs to be on the same line as the curly bracket like this } else. P1 - 1 P2 - 2 if( P2 P1) { P-P2 } else { P-P1 } Good luck, Jim anna_l wrote: Hello, I am getting an error with the following code: if( P2 P1) + { + P-P2 + } else Erro: unexpected 'else' in else { + P-P1 + } I checked the syntax so I don´t understand, I have other if else statements with the same syntax working. Thanks in advance __ 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.
Re: [R] Simple if else statement problem
Ok Jim it worked, thank you! it´s funny because it worked with the first syntax in some cases... anna_l wrote: Hello, I am getting an error with the following code: if( P2 P1) + { + P-P2 + } else Erro: unexpected 'else' in else { + P-P1 + } I checked the syntax so I don´t understand, I have other if else statements with the same syntax working. Thanks in advance -- View this message in context: http://old.nabble.com/Simple-if-else-statement-problem-tp26340336p26340642.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Simple if else statement problem
On 11/13/2009 12:54 PM, anna_l wrote: Ok Jim it worked, thank you! it´s funny because it worked with the first syntax in some cases... If R knows the whole thing is incomplete, it will accept an else on its own line. If the first 4 lines make a complete statement, R will evaluate it, and not accept the following else. So putting braces around the whole thing is another workaround, but putting the else on the same line as the first closing brace is probably better. Duncan Murdoch anna_l wrote: Hello, I am getting an error with the following code: if( P2 P1) + { + P-P2 + } else Erro: unexpected 'else' in else { + P-P1 + } I checked the syntax so I don´t understand, I have other if else statements with the same syntax working. Thanks in advance __ 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.
Re: [R] Simple if else statement problem
anna_l wrote: Ok Jim it worked, thank you! it´s funny because it worked with the first syntax in some cases... No, it did not. R doesn't randomly work in different ways on different days. -Peter Ehlers anna_l wrote: Hello, I am getting an error with the following code: if( P2 P1) + { + P-P2 + } else Erro: unexpected 'else' in else { + P-P1 + } I checked the syntax so I don´t understand, I have other if else statements with the same syntax working. Thanks in advance __ 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.
Re: [R] Simple if else statement problem
ok thanks guys for the help, indeed I assumed there was an explanation thank you duncan for giving it! -- View this message in context: http://old.nabble.com/Simple-if-else-statement-problem-tp26340336p26343665.html Sent from the R help mailing list archive at Nabble.com. __ 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.