We create data frames using the data.frame() function. This function takes vectors as arguments, and each vector becomes a column in the resulting data frame.
In the following code, we create a data frame called d1 that contains 10 rows and 3 columns.
The first column is the integer sequence from 1 to 10
The second column alternates between -1 and 1
The third column contains the sequence \(\{0.1, 0.2, \ldots, 1.0\}\).
One of the greatest strengths of data frames is their ability to store heterogeneously typed columns. For example, in the following code, we create a data frame called d3 that comprises three uniquely typed columns.
A logical vector containing 10 randomly sampled boolean values.
A character vector containing 10 random selections from the set {“foo”, “bar”}.
A numeric vector containing 10 values randomly sampled from the interval [0, 1].