How to Create Variables in R

03.18.2021

Values allow you to store information in a program which you can use later. There are two ways to store values in R. The format is the same for both: variable name, assignment operator, value.

The first way is using the <- assignment operator. Here are a few examples.

my.string <- "my string value"
my.number <- 2
my.list <- c(1, 2, 3)

In newer version of R, you can also use the = operator, which is common in many languages. Here are some examples.

my.string = "my string value"
my.number = 2
my.list = c(1, 2, 3)