What's the difference between `=` and `<-` in R?

Mehper C. Palavuzlar picture Mehper C. Palavuzlar · Feb 16, 2010 · Viewed 84.6k times · Source

I'm using R 2.8.1 and it is possible to use both = and <- as variable assignment operators. What's the difference between them? Which one should I use?

Answer

Mark Byers picture Mark Byers · Feb 16, 2010

From here:

The operators <- and = assign into the environment in which they are evaluated. The operator <- can be used anywhere, whereas the operator = is only allowed at the top level (e.g., in the complete expression typed at the command prompt) or as one of the subexpressions in a braced list of expressions.