How to assign a value to a variable in R?

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

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *