Convert a table with missing values to a data frame of the same structure as the original table?
Neither of the following methods work, as they either change the structure or do not work with missing values:
t1 <- with( mtcars, table( gear,cyl, exclude = NULL ) ) # the table
data.frame(t1)
as.data.frame(t1)
as.data.frame.table(t1)
as.data.frame.matrix(t1)
The following code works but I was hoping for a solution involving less writing:
library(reshape2)
dcast( data.frame(t1), value.var = "Freq", formula = gear ~ cyl )
The solutions to this SO question does not work with missing values: How to convert a table to a data frame
maybe I'm just too lazy. :/