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.
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
>
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.
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 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.
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.