Updated May 24, 2023
Overview of R Data Frame
Data frames are a list of vectors with equal lengths. However, the difference between matrix and data frames is that the data frames accept various types of data. (Character, numeric, etc.).
Advantages of Using Data Frames
- Distributed collection of data and organized.
- It has better optimizations compared to a relational database.
- Holds a variety of data that is heterogeneous.
Creating a Data Frame in R
We create a data_frame. Below is an example of declaring a data frame.
Data_frame <- data.frame (variable 1,variable 2, variable n…)
In the above example, we haven’t defined the variables. Let’s now see how we assign values to variables and store them in the data frame.
Number <- c(2,3,4)
alpha <- c("x","y","z")
Booleans <- c(TRUE,TRUE,FALSE)
Data_frame <- data.frame(Number,alpha,Booleans)
print(Data_frame)
Output:
Number alpha Booleans
1 2 x TRUE
2 3 y TRUE
3 4 z FALSE
Conclusion
Data frames are an important concept in R programming. Creating data sets that can be modified and accessed easily is easy yet powerful. Like a matrix, the data sets can be accessed through rows and column names, making adding and removing data easy.
Recommended Articles
In this article, we have discussed the overview, advantages, and creating a data frame in R. You may also have a look at the following articles to learn more –