[R] assign values
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Sun Nov 13 15:32:33 CET 2005
Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
> Please do read the posting guide.
> The answer to your question can be found by help("<-") or help("=").
>
> The '<-' can be used anywhere, but the '=' is
> only allowed at the top level (that is, in the complete expression
> typed by the user) or as one of the subexpressions in a braced
> list of expressions.
>
> If you don't fully understand that, just use <- always.
The text is not completely accurate though:
> if ((x=2)) 2
[1] 2
> x
[1] 2
> if (x=2) 2
Error: syntax error in "if(x="
> if(x<-2) 2
[1] 2
> if(x < -2) 2
>
We do allow "=" inside parentheses too, it's only in function
arguments (where it is ambiguous) and inside conditional clauses
(where users might use it incorrectly to test for equality) that we
disallow it.
As the last example shows, we do leave people to fry in their own fat
if they use "<-" for comparisons with negative numbers, though (been
there, done that...)
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list