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 --------------------------------- --------------------------------- [[alternative HTML version deleted]]
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] ="I guess you mean "==" .... Uwe Ligges> > Sincerely, > > Norman Goodacre > > > > --------------------------------- > > --------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > 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
Em Seg 06 Fev 2006 04:22, Norman Goodacre escreveu:> if (seq[i] = "A") m <- trans[1,]I'll guess that it is the use you are making of the name 'seq'. :-) 'seq' is an R function. Try some other name. -- Alexandre
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 GoodacrePlease, 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
Norman, you probably want: if (seq[i] == "A") m <- trans[1,] hth, Colin>>> Norman Goodacre <taranpen at yahoo.co.uk> 06/02/2006 06:22 >>>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 --------------------------------- --------------------------------- [[alternative HTML version deleted]] ______________________________________________ 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
Hi Norman ! I observe that R syntax is very close to C/C++ or Java --- Philippe Grosjean <phgrosjean at sciviews.org> a ??crit??:> 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 > > ______________________________________________ > 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 >
Patricia J. Hawkins
2006-Feb-11 21:25 UTC
[R] Turning on helpful errors in interpreter? was Re: problem with simple if() statement
Evidently, my R has some feature of error messages disabled.>>>>> "NG" == Norman Goodacre <taranpen at yahoo.co.uk> writes:NG> the following code apprantely, for some grand old reason, induces a syntax error: NG> if (seq[i] = "A") m <- trans[1,] NG> Error: syntax error in "if (seq[i] =" Where Norman gets this nice error message pointing to the exact location of the error, all I get is:> if (1=1) 5Error: syntax error>How do I turn on more-verbose error messages? Is this an environmental issue, or a build issue? This is a debian (ubuntu breezy) build; happens even when I run R --vanilla R.version _ platform i486-pc-linux-gnu arch i486 os linux-gnu system i486, linux-gnu status major 2 minor 1.1 year 2005 month 06 day 20 language R TIA! -- Patricia J. Hawkins Hawkins Internet Applications www.hawkinsia.com