I love the data.table package in R, and I think it could help me perform sophisticated cross tabulation tasks, but haven't figured out how to use the package to do tasks similar to table
.
Here's some replication survey data:
opinion <- c("gov", "market", "gov", "gov")
ID <- c("resp1", "resp2", "resp3", "resp4")
party <- c("GOP", "GOP", "democrat", "GOP")
df <- data.frame(ID, opinion, party)
In tables, counting the number of opinions by party is as simple as table(df$opinion, df$party).
I've managed to do something similar in data.table, but the result is clunky and it adds a separate column.
dt <- data.table(df)
dt[, .N, by="party"]
There's a number of grouping operations in data.table that could be great for fast and sophisticated crosstabs of survey data, but i haven't found any tutorials on how to it. Thanks for any help.