Data frames

Data frames are special lists that can also store tabular values. However, there is a constraint on the length of elements in the lists: they all have to be of a similar length. You can consider every element in the list as columns, and their lengths can be considered as rows.

Just like lists, a data frame can have objects belonging to different classes in a column; this was not allowed in matrices.

Let's quickly create a data frame using the data.frame() function:

a <- c(1, 3, 5)
b <- c("red", "yellow", "blue")
c <- c(TRUE, FALSE, TRUE)
df <- data.frame(a, b, c)
df
## a b c
## 1 red TRUE
## 3 yellow FALSE
## 5 blue TRUE

You can see the headers of a table as a, b, and c; they are the column names. Every line of the table represents a row, starting with the name of each row.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.90.12