-1

I have a data frame as below

    Users          Products
     101           Potassium Monosulfame 
     102           Kathon
     103           Tenox
     102           Potassium Monosulfame
     101           Tenox
     101           Potassium Monosulfame
     103           Kathon 
     101           Potassium Monosulfame
     103           Kathon

I want to convert this data to a matrix having Users as rows and each unique products as columns and the values as frequencies. The desired output is given below

   Users         Potassium Monosulfame    Kathon      Tenox
    101                   3                  0          1
    102                   1                  1          0
    103                   0                  2          1

Kindly guide me how to get this output in R.

Rini
  • 35
  • 8

1 Answers1

0
d <- data.frame(
Users=c( '101', '102', '103', '102', '101', '101', '103', '101', '103' ),
Products=c( 'Potassium Monosulfame', 'Kathon', 'Tenox', 'Potassium Monosulfame', 'Tenox', 'Potassium Monosulfame', 'Kathon', 'Potassium Monosulfame', 'Kathon' ))
library(reshape2)
dcast(data = d,formula = Users~Products)
Edvardoss
  • 393
  • 3
  • 8