I would like to add news columns by count of each group in type. My dataframe is like this:
#   color  type  
#   black chair       
#   black chair   
#   black sofa 
#   pink  plate
#   pink  chair
#   red   sofa    
#   red   plate   
I am looking for something like:
#   color  chair sofa plate 
#   black    2     1   0
#   pink     1     0   1
#   red      0     1   1
I used table(df$color, df$type), but the result  has no name for column 'color'