I have a data table that looks like this:
serialno state type type2
1 100 FL A C
2 100 CA A D
3 101 CA B D
4 102 GA A C
5 103 WA A C
6 103 PA B C
7 104 CA B D
8 104 CA B C
9 105 NY A D
10 105 NJ B C
I need to create a new data table that is aggregated by serialno
but calculates the count of each type of existing variables. So the end result would look like this.
FL CA GA A B C D
100 1 1 2 1 1
101 1 1 1 1
102 1 1
103 1 1 1 1 2
104 2 2 1 1
105 1 1 1 1 1 1
I'm sure there is a solution using some combination of group_by
and summarize
, but I haven't been able to figure this out. Is the easiest solution just to create first spread out the state
, type
, and type2
columns and then use summarize to create counts?