Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting a list of lists in a single list

Tags:

r

A = data.frame( a = c(1:10), b = c(11:20) )
B = data.frame( a = c(101:110), b = c(111:120) )
C = data.frame( a = c(5:8), b = c(55:58) )

L = list(list(B,C),list(A),list(C,A),list(A,B,C),list(C))

I have a list of lists of Data Frames, L but I have to creat a single List of all the Data Frames as below (The ordering of the dataframes should remain same in L and New L.)

NewL = list( B,C,A,C,A,A,B,C,C )
like image 933
user1415530 Avatar asked Jun 15 '12 09:06

user1415530


People also ask

How do I convert a list to a nested list?

Using iteration This is the novel approach in which we take each element of the list and convert it to a format of lists. We use temporary list to achieve this. Finally all these elements which are converted to lists are group together to create the required list of lists.

How do I turn a list into a single list in Python?

Flatten List of Lists Using itertools (chain()) This approach is ideal for transforming a 2-D list into a single flat list as it treats consecutive sequences as a single sequence by iterating through the iterable passed as the argument in a sequential manner.

How do I make a list in a single list?

There are a number of ways to flatten a list of lists in python. You can use a list comprehension, the itertools library, or simply loop through the list of lists adding each item to a separate list, etc. Let's see them in action through examples followed by a runtime assessment of each.


1 Answers

Try reading the manual ;) and

unlist(L,recursive=F)
like image 97
shhhhimhuntingrabbits Avatar answered Oct 23 '22 08:10

shhhhimhuntingrabbits