r/R_Programming • • Jul 25 '16

Nested list to df?

I have a list that looks like below. Problem is there is a nested list ($toLoc) inside.

[[1]]
[[1]]$timeAtLoc
[1] "2016-07-29T00:20:00"
[[1]]$id
[1] "83"
[[1]]$toLoc
[[1]]$toLoc[[1]]
[1] "LA"
[[1]]$toLoc[[2]]
[1] "NY"
[[1]]$num
[1] "3"

I think I want to get it all in a (long) df looking something like:

id timeAtLoc            toLoc
83 2016-07-26T00:26:00  LA
83 2016-07-26T00:26:00  NY

Any advice?

Thanks

2 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Aug 13 '16

Sorry for the late response. I really wouldn't be able to say unless I was playing and tinkering with it myself.

2

u/snicksn Aug 15 '16

After lots of trial and error I came up with something using lapply that was better than the loop above