这是一个清单
l1 = list(apple=c(2,23,43), pear = c(4,5), pineapple= 2, banana=97)
这是我试图从这个列表构建的data.frame
。
data.frame(fruit = c("apple","apple","apple","pear","pear","pineapple", "banana"), number = c(2,23,43,4,5,2,97))
fruit number
1 apple 2
2 apple 23
3 apple 43
4 pear 4
5 pear 5
6 pineapple 2
7 banana 97
你能帮帮我吗?
答案 0 :(得分:2)
您可以尝试melt
library(reshape2)
setNames(melt(l1), c('number', 'fruit'))
或base R
选项为stack
stack(l1)