r - Large list of lists to dataframe -


i have list of list of lists; let's call mat. want convert dataframe.

here sample contents.

[14]][[1000]] [[14]][[1000]][[1]] [1] 51  [[14]][[1000]][[2]] [1] 10  [[14]][[1000]][[3]] [1] "c hou" "c han"  [[14]][[1000]][[4]] [1] "communication middleware , software qos control in distributed real-time environmentsspecifically, consider following innovative research components "  [[14]][[1000]][[5]] [1] "compsac international computer software , applications conference" 

they are: paper id, author id, coauthor names, paper title, , journal title.

this large list generated 14 text files, , happened pick last 1 printed console, "first" index of [[14]]; "second" index of [[1000]] referring 1000th entry or record in text file, , [[1]] "index" of "column names" (paper id, author id, coauthor names, paper title, , journal title).

now, have tried few things on no luck; error error in (function (..., row.names = null, check.rows = false, check.names = true, : arguments imply differing number of rows: 1, 0 when try convert dataframe.

moreover, when use code x = mat[[1]], wanting extract 1 list of list, 1 first text files, not "view" it. view(x) produces same error: error in view : arguments imply differing number of rows: 1, 0.

i lost how convert large list dataframe can use. thanks.

i tried recreate sample data matches structure of data (i hope got right):

## create sample data: createlist <- function(j){     nelem <- 5     paperidvec <- sample.int(1000, nelem, replace = false)      authoridvec <- sample.int(1000, nelem, replace = false)      coauthorslist <- lapply(1:nelem, function(ii){                 paste("coauthor", 1:sample.int(3, 1))                        })     papertitlevec <- paste("some brilliant idea author", authoridvec, "had")     journalvec <- vapply(1:nelem, function(ii) paste("journal",                          paste(letters[sample.int(26, 3, replace = true)], collapse = "")), character(1))     outlist <- lapply(1:nelem, function(ii){                 list(paperidvec[ii], authoridvec[ii],                         coauthorslist[[ii]], papertitlevec[ii],                         journalvec[ii])                      }) } mat <- lapply(1:4, createlist) 

using data , following approach of @chinsoon12 first pasted entries create single character each entry (e.g. vector of 3 co-authors c("mr. x", "mrs. j", "mr. m") becomes "mr. x, mrs. j, mr. m"), , turned data data frames , successively combined them create 1 big data frame:

## turn nested list 1 data frame: textfiledflist <- lapply(mat, function(listlevel2) {                         ## convert list on second level of hierarchy (= 1 text file)             ## list of data frames (one each entry)                         dataframelist <- lapply(listlevel2, function(listlevel3){                         ## paste multiple entries (e.g. vector of co-authors)                         ## create single character entry:                         simplifiedlist <- lapply(listlevel3,                                  function(entries) paste(entries, collapse = ", "))                         ## create data.frame:                         outdf <- as.data.frame(simplifiedlist,                                  stringsasfactors = false,                                  col.names =  c("paper id", "author id", "coauthor names",                                          "paper title", "journal title"))                                                                         })              ## combine data frames of single entries 1 data frame,             ## containing entries of text file:             textfiledf <- do.call('rbind', dataframelist)                    }) ## combine data frames of text files 1 big data frame: bigdataframe <- do.call('rbind', textfiledflist)  > head(bigdataframe)   paper.id author.id                     coauthor.names 1      862       990             coauthor 1, coauthor 2 2      688       400                         coauthor 1 3      921       963 coauthor 1, coauthor 2, coauthor 3 4      479       455             coauthor 1, coauthor 2 5      709       340                         coauthor 1 6      936       591             coauthor 1, coauthor 2                               paper.title journal.title 1 brilliant idea author 990 had   journal pzr 2 brilliant idea author 400 had   journal mqd 3 brilliant idea author 963 had   journal wfw 4 brilliant idea author 455 had   journal tzv 5 brilliant idea author 340 had   journal dcr 6 brilliant idea author 591 had   journal egw 

Comments