I have this dataframe:
dt <- structure(list(year = c(2008L, 2008L, 2009L), name = structure(c(1L,
2L, 1L), .Label = c("stockA", "stockB"), class = "factor")), .Names = c("year",
"name"), class = "data.frame", row.names = c(NA, -3L))
I would like to produce a new df like this:
year stockA stockB
2008 1 1
2009 1 0
In order to make it I use this:
table(dt)
but it gives me only the stockA and stockB columns. How can I add the column with the years?