Create List Of Data Frames In R (Example) - Statistics Globe
Maybe your like
This tutorial explains how to make a list of data frames in the R programming language.
The table of content looks as follows:
- Example Data
- Example: How to Create a List of Data Frames
- Video & Further Resources
Here’s how to do it.
Example Data
For the example of this tutorial, I’ll use the following two data frames in R:
data1 <- data.frame(x1 = 1:3, # Create first example data frame x2 = letters[1:3]) data2 <- data.frame(y1 = c(5, 1, 5, 1, 5), # Create second example data frame y2 = rep("a", 5))The first data frame is called data1 and contains the two columns x1 and x2; The second data frame is called data2 and contains the two columns y1 and y2.
Now, let’s concatenate these two exemplifying data frames to a list in R…
Example: How to Create a List of Data Frames
In order to create a list of data frames in R, we can use the list() function. Within the function, we simply have to specify all data frames that we want to include to the list separated by a comma.
Have a look at the following R code:
my_list <- list(data1, data2) # Create list of data frames my_list # Print list to RStudio console # [[1]] # x1 x2 # 1 a # 2 b # 3 c # [[2]] # y1 y2 # 5 a # 1 a # 5 a # 1 a # 5 aAs you can see based on the output of the RStudio console, the previous R syntax created a list object called my_list, which contains our two data frames.
Video & Further Resources
Have a look at the following video of my YouTube channel. In the video tutorial, I explain the how to save and store multiple data frames in a list using the R programming codes of this page:
Furthermore, you may want to read the other posts of my website.
- Convert List of Vectors to Data Frame in R
- Merge Two Lists in R (Example)
- Merge Multiple Data Frames in List
- The R Programming Language
In summary: In this R tutorial you learned how to add multiple data frames to a list. Please let me know in the comments, in case you have further questions.
Subscribe to the Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy.
Tag » Add Df To List R
-
Append A Data Frame To A List - Stack Overflow
-
How To Add A Data Frame Inside A List In R? - Tutorialspoint
-
Insert List As Dataframe Column In R - GeeksforGeeks
-
How To Create And Manipulate Lists And Data Frames In R
-
Pandas – Append A List As A Row To DataFrame
-
R Lists: Create, Append And Modify List Components - DataMentor
-
Appending Dataframes To List Named By Variable - RStudio Community
-
How To Convert A List To A Dataframe In R - Dplyr
-
Data Wrangling: Dataframes, Matrices, And Lists | Introduction To R
-
R Data Frame: How To Create, Append, Select & Subset - Guru99
-
Appending List To Data Frame In R
-
How To Add/append An Item To A List In R? - Tutorial Kart
-
How To Append Output From A For Loop To A Dataframe In R? - ProjectPro
-
How To Add A Column To A DataFrame In R (with 18 Code Examples)