[R] difference between <- and =
spencer.graves at pdf.com
Mon Sep 1 12:37:48 CEST 2003
Thank, Peter, for the clarification: You are correct on both counts.
For the moment, I'm stuck working in an organization with many users of
"another R-like language", and I must use the same dialect as they do.
Migration is on my long-term planning horizon but won't happen soon.
Thanks also for your many interesting and useful contributions to my
education and that of many others.
Peter Dalgaard BSA wrote:
> 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.
>>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
> (Actually, that's the same thing. list() and c() are function calls like
> (almost) everything else.)
More information about the R-help