[R] if confusion
Erik Iverson
eiverson at NMDP.ORG
Mon Aug 3 22:49:32 CEST 2009
This is because you could imagine a program like the following:
tclass <- "Testing 1 2 3"
if(tclass == "Testing 1 2 3")
{
cat("Testing", tclass, "\n")
}
cat("more stuff")
However, in your program, the next line is "else", which is not a command you can just put in the middle of your program.
The solution is :
tclass <- "Testing 1 2 3"
if(tclass == "Testing 1 2 3")
{
cat("Testing", tclass, "\n")
} else {
cat(tclass, "\n")
}
Erik
-----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 3: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