[R] confused by switch() and the letter E

Andrew Bernat Andrew.Bernat at bea.doc.gov
Fri Nov 9 15:19:41 CET 2001


I can't get switch() to work as expected with the letter 'E'.  The following example from help  works just fine.

> ccc <- c("b","QQ","a","A","bb")
> for(ch in ccc) cat(ch,":",switch(ch, a=1,    b=2:3),            "\n")
b : 2 3 
QQ : 
a : 1 
A : 
bb : 

Now I replace "a=1" with "E=1"

> for(ch in ccc) cat(ch,":",switch(ch, E=1,    b=2:3),            "\n")
b : b 
QQ : QQ 
a : a 
A : A 
bb : bb 

If instead I replace "b=2:3" with "E=2:3"  I get this:
 
> for(ch in ccc) cat(ch,":",switch(ch, a=1,   E=2:3),            "\n")
Error in switch(ch, a = 1, E = 2:3) : switch: EXPR must return a length 1 vector
> 

"E" is the only letter that does this.  Even 'e' works fine.  Am I missing something obvious?  Thanks in advance for any help.   I'm using R 1.3.1 on Windows 2000.  

Kind regards,
Andy Bernat.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list