2

我有这个清单:

myList<-list(c("Developmental Biology", " Neuroscience", " Cell Biology"
), c("Developmental Biology", " Neuroscience", " Cell Biology"
), c("Developmental Biology", " Neuroscience", " Genomics & Genetics"
), c("Developmental Biology", " Neuroscience", " Cell Biology"
), c("Developmental Biology", " Neuroscience", " Cell Biology"
), c("Developmental Biology", " Genomics & Genetics"))

我想要这个数据框:

     [,1]                    [,2]                   [,3]                   
[1,] "Developmental Biology" " Neuroscience"        " Cell Biology"        
[2,] "Developmental Biology" " Neuroscience"        " Cell Biology"        
[3,] "Developmental Biology" " Neuroscience"        " Genomics & Genetics" 
[4,] "Developmental Biology" " Neuroscience"        " Cell Biology"        
[5,] "Developmental Biology" " Neuroscience"        " Cell Biology"        
[6,] "Developmental Biology" " Genomics & Genetics" "NA"

我原以为 rbind.fill 将是要走的路,但do.call(rbind.fill,myList)返回NULL.

4

1 回答 1

3

该函数rbind.fill只能合并数据帧。但是列表中的元素myList是字符向量。在使用之前需要将它们转换为数据帧rbind.fill

这可以解决问题:

library(plyr)
rbind.fill(lapply(myList, function(x) as.data.frame(t(as.matrix(x)))))

#                      V1                   V2                   V3
# 1 Developmental Biology         Neuroscience         Cell Biology
# 2 Developmental Biology         Neuroscience         Cell Biology
# 3 Developmental Biology         Neuroscience  Genomics & Genetics
# 4 Developmental Biology         Neuroscience         Cell Biology
# 5 Developmental Biology         Neuroscience         Cell Biology
# 6 Developmental Biology  Genomics & Genetics                 <NA>
于 2012-11-08T13:53:33.950 回答