Suppose I have a list
of different sized vectors that look like this:
> test
[[1]]
[1] 1
[[2]]
[1] 1 2 3 4
[[3]]
[1] 1 2 3 4 5 6 7
What would be the best way to transform this into a data.frame
with each list
element as a column, while filling in missing rows with NA like so?
> test2
V1 V2 V3
1 1 1 1
2 NA 2 2
3 NA 3 3
4 NA 4 4
5 NA NA 5
6 NA NA 6
7 NA NA 7
When I run do.call(cbind.fill,test)
, I get this:
V1 V1 V1
1 1 1 1
2 1 2 2
3 1 3 3
4 1 4 4
5 1 1 5
6 1 2 6
7 1 3 7
Trying suggestion:
> do.call(rbind.data.frame, test)
c.1L..1L..1L. c.1L..2L..2L. c.1L..3L..3L. c.1L..1L..4L. c.1L..2L..5L. c.1L..3L..6L. c.1L..1L..7L.
1 1 1 1 1 1 1 1
2 1 2 3 1 2 3 1
3 1 2 3 4 5 6 7