I have an R problem. I would like to count factors of a variable depending of an other variable in a dataframe.
I give you an example:
I have
ID com
125 nul
125 nul
125 dec
125 asc
125 0
130 nul
130 dec
What I want
ID|nul|dec|asc|0
125|2|1|1|1
130|1|1|0|0
NB: the variable com
is a factor, and ID
is intger.
I tried the easy way that I know: table(df$ID, df$com)
but it hasn't worked.