[R] Is there any difference between <- and =

HBaize HBaize at buttecounty.net
Fri Mar 13 03:36:20 CET 2009

I think most people find it odd at first if they have always used "=" but
quickly you get use to it and nothing could be more clear. It is explicit.
It is active and provides a direction, a value goes into an object. The
equal sign for assignment is ambiguous. 

As an example 

 x = 3

we only know that the value 3 is assigned to the object x because by
convention a number cannot be an object, if not it could be read as the
object "3" taking the value "x" The expression literally states that they
are equal, yet you cannot assume that all instances of 3 are equal to x, so
it is an inaccurate expression. On the other hand,

3 -> x  or 
x <- 3  

is very clear. It makes no changes to "3" only to "x"  I've been reading
"Data Manipulation with R" and find the author's use of "=" for assignment
disturbing. You quickly get use to -> and will find after a short time that
you prefer it.

Sean Zhang wrote:
> Dear R-helpers:
> I have a question related to <- and =.
> I saw very experienced R programmers use = rather than <- quite
> consistently.
> However, I heard from others that do not use = but always stick to <- when
> assigning valuese.
> I personally like = because I was using Matabl, But, would like to receive
> expert opinion to avoid potential trouble.
> Many thanks in advance.
> -Sean
> 	[[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

View this message in context: http://www.nabble.com/Is-there-any-difference-between-%3C--and-%3D-tp22456167p22489108.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list