My data looks a bit like this:
Q1 Q2 Q3 Q4
S NS S S
NS . S PMI
S S TMI S
PMI S S NS
The only options are S, TMI, PMI, NS (or missing, which is a .). I would like it to look like this (df called PCP):
Q1 Q2 Q2 Q4
S 2 2 3 2
NS 1 1 0 1
PMI 1 0 0 1
TMI 0 0 1 0
. 0 1 0 0
I can do it in 2 steps with this code:
Counts <- melt(table(PCP$Q1)) %>%
join(y = melt(table(PCP$Q2)), type = "full") %>%
join(y = melt(table(PCP$Q3)), type = "full") %>%
join(y = melt(table(PCP$Q4)), type = "full")
Counts <- melt(Counts, key='Var1')
Bur is there a nice way of doing this in one step maybe using dplyr/plyr packages?