【发布时间】:2017-09-21 06:26:13
【问题描述】:
我有一个如下的数据框
Users Products
101 Potassium Monosulfame
102 Kathon
103 Tenox
102 Potassium Monosulfame
101 Tenox
101 Potassium Monosulfame
103 Kathon
101 Potassium Monosulfame
103 Kathon
我想将此数据转换为一个矩阵,其中用户为行,每个唯一产品为列,值作为频率。所需的输出如下所示
Users Potassium Monosulfame Kathon Tenox
101 3 0 1
102 1 1 0
103 0 2 1
请指导我如何在 R 中获得此输出。
【问题讨论】:
-
table(df$Users, df$Products)
标签: r