我有这个清单:
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
。
答案 0 :(得分: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>