VOOZH about

URL: https://www.geeksforgeeks.org/r-language/convert-list-of-lists-to-dataframe-in-r/

⇱ Convert list of lists to dataframe in R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Convert list of lists to dataframe in R

Last Updated : 30 May, 2021

In this article, we will discuss how to convert a list of lists to dataframe in R Programming Language. We will convert a list of lists to a data frame both by row and by column.

Example 1: R program to create three lists inside a list with numeric and character type and convert into dataframe by column.

Syntax as.data.frame(do.call(cbind, list_name))

Parameters: Where cbind is to convert list to dataframe by column and list_name is the input list which is list  of lists

Code:

Output:

 list1 list2 list3
1 1 a 2
2 2 b 3
3 3 c 4
4 4 d 5
5 5 e 6

Example 2: R program to create two lists inside a list with numeric and character type and convert into dataframe by column

Output:

 list1 list2
1 1 a
2 2 b
3 3 c
4 4 d
5 5 e

Example 3: R program to create three lists inside a list with numeric and character type and convert into dataframe by column.

Syntax: as.data.frame(do.call(rbind,list_name))

Parameters: Where rbind is to convert list to dataframe by row and list_name is the input list which is list  of lists

Output:

 V1 V2 V3 V4 V5
list1 1 2 3 4 5
list2 a b c d e
list3 2 3 4 5 6
Comment

Explore