← Back to R Course | Chapter 2: Variables & Types | Lesson 1 of 7

Assignment Operators

In this page:

  1. Assignment Operators

Assignment Operators

R conventionally uses <- for assignment, though = also works in most contexts. <- is preferred by style guides because it's unambiguous everywhere, including inside function calls where = has a different meaning (naming an argument). The right-pointing -> is also valid and assigns from left to right.

Warning: Inside a function call, f(x = 1) sets a named argument, not a variable assignment -- use <- when you actually mean assignment.

Example: Assignment Operators

markup
x <- 10
y = 20
30 -> z

cat(x, y, z, "\n")
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.