I have the following:
Type State
A California
B Washington
A California
A California
A Washington
B New York
I would like to do a pivot in R to find out the number of each type in each state.
I have figured out how to find out the number of each type (without state breakdown) by using:
table(df$Type)
This gives me the following result:
Var1 Freq
A 4
B 2
However, I would like to add a second dimension such that I can get a state breakdown of the above result. A suggested output would look like this:
California Washington New York Total
A 3 1 0 4
B 0 1 1 2
Does anyone know how to do something like this?