A First R Session

Let’s make a simple data set (in R parlance, a vector) consisting of the numbers 1, 2, and 4, and name it x:

> x <- c(1,2,4)

The standard assignment operator in R is <-. You can also use =, but this is discouraged, as it does not work in some special situations. Note that there are no fixed types associated with variables. Here, we’ve assigned a vector to x, but later we might assign something of a different type to it. We’ll look at vectors and the other types in Section 1.4.

The c stands for concatenate. Here, we are concatenating the numbers 1, 2, and 4. More precisely, we are concatenating three one-element vectors that consist of those numbers. This is because any number is also considered to be a one-element vector.

Now ...

Get The Art of R Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.