【发布时间】:2016-06-10 18:51:49
【问题描述】:
我有一个列表列表,我需要将其转换为相应的数据框。
行的位置很重要,这样我以后可以将它们链接到另一个项目。我尝试了一种将其放入数据框的方法,但由于某些行为 NULL,我不能这样做。
first = c(1,2,3)
second = c(1,2)
problemrows = NULL
mylist = list(first,second,problemrows)
#mylist - should turn into a dataframe with each row being same order as the list of lists. NULL value would be a null row
library(plyr) # doesn't work because of NULLs above
t(plyr::rbind.fill.matrix(lapply(mylist, t)))
## help^^^ Ideally the row that doesn't work would just be a null row or the new dataframe would remove these NULL lists as rows and instead assign appropriate row#s to everything else to make up for what was skipped.
# other approach - change all the NULL list of lists to something like -999 which is another fix.
【问题讨论】:
标签: r list plyr nested-lists