[R] if/else scope

Ben Tupper btupper at bigelow.org
Wed Nov 16 02:31:37 CET 2011


Hi,

Check out this R-help thread from 2007.

http://tolstoy.newcastle.edu.au/R/e2/help/07/06/19513.html

Cheers,
Ben


On Nov 15, 2011, at 6:46 PM, Kevin Burton wrote:

> What is wrong with the following?
> 
> 
> 
> x <- 1:2
> 
> if(x[1] > 0)
> 
> {
> 
>                if(x[2] > 0)
> 
>                {
> 
>                                print("1 & 2 > 0")
> 
>                }
> 
>                else
> 
>                {
> 
>                                print("1 > 0")
> 
>                }
> 
> }
> 
> else
> 
> {
> 
>                if(x[2] > 0)
> 
>                {
> 
>                                print("2 > 0")
> 
>                }
> 
>                else
> 
>                {
> 
>                                print("NONE > 0")
> 
>                }
> 
> }
> 
> 
> 
> Gives me
> 
> 
> 
> Error: unexpected 'else' in "else"
> 
> 
> 
> What am I missing?
> 
> 
> 
> Kevin
> 
> 
> 	[[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
180 McKown Point Rd. P.O. Box 475
West Boothbay Harbor, Maine   04575-0475 
http://www.bigelow.org



More information about the R-help mailing list