0

I have a rather complex list of lists of data frames that I want to unnest and make a simple data frame from, with each column representing a column in the nested data frames. The data looks like this:

enter image description here

"percents" is the name of the entire list of 93 elements. Each element is a list of 4 data frames, each with 19 variables. Every time I try to unnest it, I get an error that says "no applicable method for unnest applied to an object of class list". What do I have to do to get this to unnest itself?

user8229029
  • 883
  • 9
  • 21
  • Are you sure this hasn't been asked and answered multiple times? https://stackoverflow.com/questions/16672645/convert-a-nested-list-to-a-list – IRTFM Mar 11 '21 at 20:28
  • Yes, that answer does not work for me, and I have checked several other questions. – user8229029 Mar 11 '21 at 20:35
  • reproducible example will really help - https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Bulat Mar 11 '21 at 20:41
  • I do not see any reason why `do.call(rbind, lapply(percents, function(chunks){ do.call( rbind, lapply(chunks, unlist) ) } ))` would not work. It appears to simple be a doubly nested list so doing the same opation twice should suffice. Prove me wrong by putting in a simple test case constructed with code. – IRTFM Mar 11 '21 at 20:43
  • That's what I just did before I saw your comment, and it's extremely fast and works. do.call(cbind.data.frame, percents) – user8229029 Mar 11 '21 at 20:48
  • So you want these side by side rather than stacked. Same difference I suppose. You may need to adjust column names. – IRTFM Mar 11 '21 at 21:27

0 Answers0