1

The list of lists that I have has 104 lists which in turn have 36 elements each. I was looking to convert this to a data frame with 104 rows and 36 columns while retaining the names of the columns.

Something like the following example:

x <- list("a"=1,"b"=2,"c"=3)
y <- list("a"=2,"b"=4,"c"=1)
z <- list("a"=1,"b"=6,"c"=9)
lst <- list("A" = x, "B" = y, "C" = y)

What I am trying to get is:

  a b c
A 1 2 3
B 2 4 1
C 3 1 9 

With the names for the rows and columns

Using the answer shown here

K_D
  • 147
  • 8

1 Answers1

4

We can use

m1 <- t(simplify2array(lst))
akrun
  • 874,273
  • 37
  • 540
  • 662
  • Hello thanks for the reply! Your solution worked very well in rearranging the data but with my data, the names are still not available. The rows are named V1,V2,V3... and the columns are numbered 1,2,3,4. However, it worked perfectly for the example I used. I compared the properties of the example list above with my dataset and I didn't find any differences. Both are list of lists with a name for the list (lst), names for the sub-lists (A,B,C) and the elements of each sub-list with labels (a,b,c). – K_D Jan 20 '20 at 09:45
  • @K_D It is based on your example. If you can show a better example, would check it – akrun Jan 20 '20 at 16:16