Naming things

We can assign labels to the results of calculations and other parts of our analyses to keep track of them.

To assign labels we use the <- symbol. The <- symbol points from the value we want to store, to the name we want to use. For example:

the_magic_number <- 3

This assigns the value 3 to the variable the_magic_number.

This block wouldn’t display anything because assigning a variable doesn’t create any output.

To both assign a variable and display it we would type:

the_magic_number <- 3
the_magic_number
[1] 3

Or we can use a shortcut: if we wrap the line in parentheses this both makes the assignment and prints the result to the console:

(i_am_a_new_variable <- 22)
[1] 22

We can also do calculations as we assign variables:

one_score <- 20
(four_score_years_and_ten <- one_score * 4 + 10)
[1] 90

We can give anything a label by assigning it to a variable.

It doesn’t have to be a number; we can also assign letters, words, graphics, the results of a statistical model, or lists of any of these things.

This will come in handy later.