gpt4 book ai didi

r - 将列中的数据转换为 R 中的事务

转载 作者:行者123 更新时间:2023-12-04 10:32:31 25 4
gpt4 key购买 nike

<分区>

我有销售数据,即消费者购买了哪些商品的信息。我需要将其转化为交易数据以进行亲和性分析。

数据是这样的:

ID=c("A123","A123","A123","A123","B456","B456","B456")
item=c("bread", "butter", "milk", "eggs", "meat","milk", "peas")

data.frame(cbind(ID, item))
ID item
1 A123 bread
2 A123 butter
3 A123 milk
4 A123 eggs
5 B456 meat
6 B456 milk
7 B456 peas

但是我怎样才能把它变成这种形式呢?:

  ID  basket
A123 bread,butter,milk,eggs
B456 meat,milk,peas

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com