Creating a data frame and accessing its properties
A data frame in R is also a two-dimensional arrangement like a matrix, but it can contain a combination of data types in different columns. One column could be numeric, another column could be character. A data frame can be considered as a natural generalization of a matrix in R. In this recipe, you will learn how to create a data frame and how to access various columns and/or elements of it.
Getting ready
Since you have already learned to create a matrix, it will be relatively simple to understand the data frame. It is good to have an understanding of variables and datasets. Though the structure of a data frame is similar to a matrix, it has more information within it.
How to do it…
Let's take a look at the following steps to learn how to create a data frame in R:
- To create a data frame in R, you will have to use a function called
data.frame()
. This function is the convenient way to create a data frame. Within thedata.frame()
function, it contains...