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 に答える