4.3 Lists

You are not limited to storing just one value in a variable. For example, you could put the numbers 1 to 10 into \(x\) with the following code:

x <- 1:10
x

We can be more precise to change the increment to a different number.

x <- seq(from = 1, to = 10, by = 0.5)
x

Note that the from, to, and by are not required syntax, but is included here for better understandability of the code, as shown in the example that follows.

x1 <- seq(1, 10, 0.5)
x1

We could have a vector where the numbers do not follow any logical sequence, such as:

x <- c(1, 6, 9)
x

Here the notation c() is a way to combine data into one list. This example combines numbers, but this c() function also combines text.