Umm sorry to bother everyone again but I'm having trouble with my if
statement. I come from a perl background so that's probably my problem! :)
So here is my code:
if (any(lgAB>4) | any(lgAB<-4)){
freq_AB<-hist(lgAB, type="o", plot=F)
else
freq_AB<-hist(lgAB, breaks=br,type ="o", plot=F)
}
And I get > source("E:/R/GMDA-1.1.R")
Error in parse(file, n = -1, NULL, "?") : syntax error at
11: freq_AB<-hist(lgAB, type="o", plot=F)
12: else>
Thanks again,
You need more brackets:
if(blah) {
do something
} else {
do something different
}
Sarah
PS Using underscores in variable names is not encouraged, and
can cause you problems in certain contexts.
On 6/13/06, H. Paul Benton <hpbenton@scripps.edu>
wrote:>
> Umm sorry to bother everyone again but I'm having trouble with my if
> statement. I come from a perl background so that's probably my problem!
:)
> So here is my code:
>
> if (any(lgAB>4) | any(lgAB<-4)){
> freq_AB<-hist(lgAB, type="o", plot=F)
> else
> freq_AB<-hist(lgAB, breaks=br,type ="o", plot=F)
> }
>
--
Sarah Goslee
[[alternative HTML version deleted]]
replace 'else' with '} else {'
Gabor
On Tue, Jun 13, 2006 at 11:18:00AM -0700, H. Paul Benton
wrote:> Umm sorry to bother everyone again but I'm having trouble with my if
> statement. I come from a perl background so that's probably my problem!
:)
> So here is my code:
>
> if (any(lgAB>4) | any(lgAB<-4)){
> freq_AB<-hist(lgAB, type="o", plot=F)
> else
> freq_AB<-hist(lgAB, breaks=br,type ="o", plot=F)
> }
>
> And I get
> > source("E:/R/GMDA-1.1.R")
> Error in parse(file, n = -1, NULL, "?") : syntax error at
> 11: freq_AB<-hist(lgAB, type="o", plot=F)
> 12: else
> >
>
> Thanks again,
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
--
Csardi Gabor <csardi at rmki.kfki.hu> MTA RMKI, ELTE TTK
H. Paul Benton wrote:> Umm sorry to bother everyone again but I'm having trouble with my if > statement. I come from a perl background so that's probably my problem! :) > So here is my code: > > if (any(lgAB>4) | any(lgAB<-4)){ > freq_AB<-hist(lgAB, type="o", plot=F) > else > freq_AB<-hist(lgAB, breaks=br,type ="o", plot=F) > } > > And I get > > source("E:/R/GMDA-1.1.R") > Error in parse(file, n = -1, NULL, "?") : syntax error at > 11: freq_AB<-hist(lgAB, type="o", plot=F) > 12: else > >No-one yet has pointed out the following problem, which, while not be a syntax error as such, will cause you headaches: if (any(lgAB>4) | any(lgAB<-4)){ ^^^^^^^ This assigns the value 4 to lgAB (which is presumably NOT what you want to do). You want ``any(lgAB < -4)''. General rule: Put in spaces around operators --- it makes the code (much) more readable and avoids unintended consequences. Another infelicity in your code: ``plot=F''. Use ``plot=FALSE''. (Note that the symbols ``F'' and ``T'' are assignable, *unlike* ``TRUE'' and ``FALSE''.) cheers, Rolf Turner rolf at math.unb.ca