R项组合 [英] R item combinations
本文介绍了R项组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用R,想找到消费者之间最常见的对。
I'm using R and want to find the most common pairs between consumers.
consumer=c(1,1,1,1,1,2,2,2,2,3,3,4,4,4,4,5)
items=c("apple","banana","carrot","date","eggplant","apple","banana","fig","grape","apple","banana","apple","carrot","date","eggplant","apple")
shoppinglists <- data.frame(consumer,items)
有没有办法看到苹果+香蕉出现在三个名单(消费者1和4)?
Is there a way to see that "apple"+"banana" appears on three lists (consumers 1,2 and 3) and "apple"+"carrot" appears on two lists (consumers 1 and 4)?
推荐答案
你可以看到这里的信息:
You can see that information here:
tbl <- table(shoppinglists)
t(tbl) %*% tbl
# items
#items apple banana carrot date eggplant fig grape
# apple 5 3 2 2 2 1 1
# banana 3 3 1 1 1 1 1
# carrot 2 1 2 2 2 0 0
# date 2 1 2 2 2 0 0
# eggplant 2 1 2 2 2 0 0
# fig 1 1 0 0 0 1 1
# grape 1 1 0 0 0 1 1
看到苹果配对香蕉3次,胡萝卜2次,查看第一行或第一列。
To see that apple pairs up with banana 3 times and carrot 2 times, look in the first row or the down the first column.
这篇关于R项组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文