[R] if confusion

David Huffer David.Huffer at csosa.gov
Mon Aug 3 22:49:01 CEST 2009


Because the line if... Is syntactically complete. Move the else statement to the line above it like

tclass <- "Testing 1 2 3"
if ( tclass == "Testing 1 2 3" )
{
    cat ( "Testing" , tclass , "\n" )
} else
{
    cat ( tclass , "\n" )
}

david


--
 David
 
 -----------------------------------------------------
 David Huffer, Ph.D.               Senior Statistician
 CSOSA/Washington, DC           david.huffer at csosa.gov
 -----------------------------------------------------



-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of rkevinburton at charter.net
Sent: Monday, August 03, 2009 4:41 PM
To: r-help at r-project.org
Subject: [R] if confusion

Simple question:

Why doesn't the following work? Or what 'R' rule am I missing?

tclass <-  "Testing 1 2 3"
if(tclass == "Testing 1 2 3")
{
    cat("Testing", tclass, "\n")
}
else
{
    cat(tclass, "\n")
}

I get an error 'else' is unexpected.

Thank you.

Kevin

______________________________________________
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