- Using the assignment operator
<-
, e.g.,my_var <- 1—
the most common way of assigning a value to a variable in R. - Using the equal operator
=
, e.g.,my_var = 1
—for assigning values to arguments inside a function definition. - Using the rightward assignment operator
->
, e.g.,my_var -> 1
—can be used in pipes. - Using the global assignment operators, either leftward (
<<-
) or rightward (->>
), e.g.,my_var <<- 1
—for creating a global variable inside a function definition.
How to assign a value to a variable in R?