Opening the book…
A variable is a symbol that stands for another value (just like “X” in algebra). We can create a variable by assigning a value to it using the <- operator. If we then type the name of the variable R will print out its value.
> x <- 4
> x
[1] 4
The variable now stands for the value that it contains, so we can perform operations on it and get the same answer as if we used the value itself.
> x + 3
[1] 7
> x == 5
[1] FALSE
We can change the value of a variable by simply assigning a new value to it.
> x <- x + 1
> x
[1] 5
A note: You can also use the equals sign = instead of the <-
This page titled 3.4: Variables was last modified on Mon, 11 Jan 2021 05:16:30 GMT and is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Russell A. Poldrack via source content that was edited to the style and standards of the LibreTexts platform.
The book could not be loaded just now.