[R] assign

Duncan Murdoch murdoch.duncan at gmail.com
Fri Jul 16 17:03:57 CEST 2010


On 16/07/2010 10:57 AM, linda.s wrote:
> Hi.
> I am a beginner. What is the difference between:
> x<-2
> and
> x=2
>   

It depends on the context.  "x <- 2" always assigns the value 2 to the 
variable named x.  Typed as an isolated command, that's what "x = 2" 
does too.  However, when used as an argument to a function, e.g. f(x = 
2), it associates the value 2 to the *argument* matched by x in the 
function call.  This is occasionally confusing, so many people recommend 
that you always use "x <- 2" when you mean to do an assignment, and 
reserve the use of "=" for function arguments.

Duncan Murdoch



More information about the R-help mailing list