Skip to content
Prev 377769 / 398502 Next

Combine lists into a data frame or append them to a text file

Hi Ek,
I thought there would be a simple fix for this, but had to write a
little function:

fillList<-function(x) {
 maxrows<-max(unlist(lapply(x,length)))
 return(lapply(x,"[",1:maxrows))
}

that fills up the rows of each list with NAs. I got the expected result with:

testlist<-list(a=1:8,b=1:9,c=1:10)
as.data.frame(fillList(testlist))

so:

for (i in 1:length(MyTables)) {
write.table(as.data.frame(fillList(MyTables[i])),
 file = "Temp.txt",append = TRUE,quote = TRUE)

may do the job.

Jim
On Sun, Dec 16, 2018 at 2:28 PM Ek Esawi <esawiek at gmail.com> wrote: