我正在尝试使用在交易中购买的物品的现有数据框在 R 中创建一个新的数据框,如下所示:
数据的 dput 输出:
structure(list(Transaction = c(1L, 2L, 2L, 3L, 3L, 3L), Item = c("Bread",
"Scandinavian", "Scandinavian", "Hot chocolate", "Jam", "Cookies"
), date_time = c("30/10/2016 09:58", "30/10/2016 10:05", "30/10/2016 10:05",
"30/10/2016 10:07", "30/10/2016 10:07", "30/10/2016 10:07"),
period_day = c("morning", "morning", "morning", "morning",
"morning", "morning"), weekday_weekend = c("weekend", "weekend",
"weekend", "weekend", "weekend", "weekend"), Year = c("2016",
"2016", "2016", "2016", "2016", "2016"), Month = c("October",
"October", "October", "October", "October", "October")), row.names = c(NA,
6L), class = "data.frame")
正如您在示例中看到的那样,这些行是由于购买的每个单独的产品,而不是交易本身(因此交易 2 是第 2 行和第 3 行)。
我想创建一个新表,其中行是不同的事务(1、2、3 等),不同的列是分类的(面包 = 0、1),所以我可以执行先验分析。
知道如何将不同的交易组合在一起,然后创建这些新列吗?