[R] difference between <- and =
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Mon Sep 1 12:23:32 CEST 2003
Spencer Graves <spencer.graves at pdf.com> writes:
> A common, punishing error for me, with DF being a data
> frame, is the following:
>
> if(DF$a = 1) ...
>
> where I intended to write "if(DF$a == 1)...". This error
> first replaces column "a" of DF with the trivial vector 1 (of length
> 1), and then interprets that as a logical, which evaluates as TRUE.
> Unless the "if" statement otherwise generates an error, I must restore
> column "a" from somewhere before I can continue.
Eh?
> a <- list(x=2)
> if (a$x = 1) 5
Error: syntax error
I think you're referring to another R-like language....
> In addition to specifying function arguments, I also use
> "=" to specify named components of a list or a vector. That works
> fine for me. It's only the accidental use of "=" when I mean "==" that
> creates problems.
(Actually, that's the same thing. list() and c() are function calls like
(almost) everything else.)
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list