I have the following List named test
that I am trying to turn into a data.frame()
test <- structure(list(Feb.19.2016 = structure(list(calls = structure(list(
Strike = c(2.5, 5, 7.5), Last = c(0.5, 0.31, 0.45), Chg = c(-0.1,
0, 0), Bid = c(0.5, 0.1, 0), Ask = c(0.75, 0.35, 0.4), Vol = c(2L,
5L, 6L), OI = c(273L, 38L, 12L)), .Names = c("Strike", "Last",
"Chg", "Bid", "Ask", "Vol", "OI"), row.names = c("ATNM160219C00002500",
"ATNM160219C00005000", "ATNM160219C00007500"), class = "data.frame"),
puts = structure(list(Strike = c(2.5, 5), Last = c(0.95,
3), Chg = c(-0.15, 0), Bid = c(0.75, 2.75), Ask = c(1.1,
3.5), Vol = c(20L, 10L), OI = c(48L, 26L)), .Names = c("Strike",
"Last", "Chg", "Bid", "Ask", "Vol", "OI"), row.names = c("ATNM160219P00002500",
"ATNM160219P00005000"), class = "data.frame")), .Names = c("calls",
"puts"))), .Names = "Feb.19.2016")
When I try to convert it to data.frame
: df <- as.data.frame(test)
I get the following error:
Error in data.frame(calls = list(Strike = c(2.5, 5, 7.5), Last = c(0.5, :
arguments imply differing number of rows: 3, 2
I want to turn my list (test
) into a data.frame()
and let any missing fields be NA:
Desired Output:
Strike Last Chg Bid Ask Vol OI Strike Last Chg Bid Ask Vol OI
ATNM160219C00002500 2.5 0.50 -0.1 0.5 0.75 2 273 2.5 0.95 -0.15 0.75 1.1 20 48
ATNM160219C00005000 5.0 0.31 0.0 0.1 0.35 5 38 5.0 3.00 0.00 2.75 3.5 10 26
ATNM160219C00007500 7.5 0.45 0.0 0.0 0.40 6 12 NA NA NA NA NA NA NA