How To Add A Data Frame Inside A List In R? - Tutorialspoint
Maybe your like
- Home
- Whiteboard
- Online Compilers
- Practice
- Articles
- AI Assistant
- Jobs
- Tools
- Corporate Training
- Courses
- Certifications
- Switch theme
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
A list may contain many objects such as vector, matrix, data frame, list etc. In this way, we can have access to all the necessary objects at the same time. If we want to add a data frame inside a list then we can use the length of the list. For example, if we have a list defined as List and we want to add a data frame df to the List then it can be added as follows −
List[[length(List)+1]]<−dfExample1
df1<−data.frame(x=rnorm(20,1,0.004)) df1Output
x 1 1.0103338 2 0.9959405 3 1.0018717 4 1.0056090 5 1.0014642 6 1.0042043 7 0.9939947 8 1.0021608 9 0.9993048 10 0.9972184 11 0.9912667 12 0.9964343 13 0.9979993 14 0.9935636 15 0.9990263 16 1.0002390 17 1.0004094 18 1.0034078 19 1.0044146 20 1.0026450 List1<−list(letters[1:26]) List1 [[1]] [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" [20] "t" "u" "v" "w" "x" "y" "z"Adding df1 inside List1 −
List1[[length(List1)+1]]<−df1 List1Output
[[1]] [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" [20] "t" "u" "v" "w" "x" "y" "z" [[2]] x 1 1.0103338 2 0.9959405 3 1.0018717 4 1.0056090 5 1.0014642 6 1.0042043 7 0.9939947 8 1.0021608 9 0.9993048 10 0.9972184 11 0.9912667 12 0.9964343 13 0.9979993 14 0.9935636 15 0.9990263 16 1.0002390 17 1.0004094 18 1.0034078 19 1.0044146 20 1.0026450Example2
df2<−data.frame(x=rpois(20,4)) df2Output
x 1 1 2 2 3 5 4 3 5 9 6 5 7 4 8 5 9 5 10 5 11 6 12 4 13 5 14 1 15 2 16 5 17 5 18 3 19 4 20 6 List2<−list(sample(0:9,50,replace=TRUE)) List2 [[1]] [1] 1 4 2 2 7 4 2 7 2 1 2 6 3 0 5 1 9 6 2 3 8 2 9 0 8 5 2 2 3 8 3 6 8 5 5 5 6 9 [39] 3 6 4 9 0 2 0 8 0 9 7 2Adding df2 inside List2 −
List2[[length(List2)+1]]<−df2 List2Output
[[1]] [1] 1 4 2 2 7 4 2 7 2 1 2 6 3 0 5 1 9 6 2 3 8 2 9 0 8 5 2 2 3 8 3 6 8 5 5 5 6 9 [39] 3 6 4 9 0 2 0 8 0 9 7 2 [[2]] x 1 1 2 2 3 5 4 3 5 9 6 5 7 4 8 5 9 5 10 5 11 6 12 4 13 5 14 1 15 2 16 5 17 5 18 3 19 4 20 6
Nizamuddin Siddiqui Updated on: 2020-11-07T11:48:56+05:30 3K+ Views
Kickstart Your Career
Get certified by completing the course
Get StartedTag » Add Df To List R
-
Append A Data Frame To A List - Stack Overflow
-
Create List Of Data Frames In R (Example) - Statistics Globe
-
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)