[R] problem with simple if() statement

Philippe Grosjean phgrosjean at sciviews.org
Mon Feb 6 11:22:06 CET 2006


Norman Goodacre wrote:
> the following code apprantely, for some grand old reason, induces a syntax error:
>   
>   if (seq[i] = "A") m <- trans[1,]
>   
>   where seq is a vector and trans is a matrix. I cannot for the life of me see why this is wrong. Syntax error is: 
>   
>   Error: syntax error in "if (seq[i] ="
>   
>   Sincerely,
>   
>   Norman Goodacre

Please, read "An Introduction to R" provided with any version of R. The 
correct syntax for an equality condition is "==", not "=", so:

 > if (seq[i] == "A") ....

Best,

Philippe Grosjean




More information about the R-help mailing list