- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create data frame using nested list elements in R?
To create data frame using nested list elements, we would need to unlist the list elements and store them in a matrix then read as a data frame using data.frame function. For example, if we have a nested called LIST then the data frame can be created by using the command −
data.frame(matrix(unlist(LIST),ncol=”No of columns we want”,byrow=F))
Check out the below example to understand how it works.
Example
nestedList<-list(list(x1=rpois(20,2),x2=rpois(20,2)),list(y1=rpois(20,2),y2=rpois(20,2))) nestedList
Output
[[1]] [[1]]$x1 [1] 1 1 4 5 1 2 1 0 1 1 0 3 2 3 0 2 3 2 1 2 [[1]]$x2 [1] 2 4 0 2 2 2 1 0 3 1 3 1 2 2 2 3 3 4 3 0 [[2]] [[2]]$y1 [1] 1 0 1 2 3 1 2 2 2 2 3 2 3 3 4 3 3 2 3 4 [[2]]$y2 [1] 0 1 3 2 1 0 2 2 5 2 1 0 1 4 0 1 1 3 1 1
data.frame(matrix(unlist(nestedList),ncol=2,byrow=F))
X1 X2 1 1 1 2 1 0 3 4 1 4 5 2 5 1 3 6 2 1 7 1 2 8 0 2 9 1 2 10 1 2 11 0 3 12 3 2 13 2 3 14 3 3 15 0 4 16 2 3 17 3 3 18 2 2 19 1 3 20 2 4 21 2 0 22 4 1 23 0 3 24 2 2 25 2 1 26 2 0 27 1 2 28 0 2 29 3 5 30 1 2 31 3 1 32 1 0 33 2 1 34 2 4 35 2 0 36 3 1 37 3 1 38 4 3 39 3 1 40 0 1
- Related Articles
- How to create a data frame in R with list elements?
- How to create scatterplot using data frame columns in R?
- How to create boxplot for list elements using ggplot2 in R?
- How to create an empty data frame in R?
- How to create barplot from data frame in R using rows as categories?
- How to create a categorical variable using a data frame column in R?
- How to create a data frame of the maximum value for each group in an R data frame using dplyr?
- How to create a data frame with one or more columns as a list in R?
- How to convert rows in an R data frame to list?
- How to convert a list to a data frame in R?
- How to create a single data frame from data frames stored in a list with row names in R?
- How to add a data frame inside a list in R?
- How to create a 3D-array from data frame in R?
- How to create a group column in an R data frame?
- How to create a lagged column in an R data frame?

Advertisements