小编muk*_*und的帖子

将数据从一张有条件的表中分到不同的表中

我正在用 R 对几种产品进行交叉销售分析。我已经转换了交易数据,它看起来像这样 -

  df.articles <- cbind.data.frame(Art01,Art02,Art03)

  Art01         Art02      Art03
  bread         yoghurt    egg
  butter        bread      yoghurt
  cheese        butter     bread
  egg           cheese     NA
  potato        NA         NA

 Actual data is 'data.frame': 69099 obs. of  33 variables.
Run Code Online (Sandbox Code Playgroud)

我想要列出所有不同的物品及其与物品一起出售的数量(在这种情况下是面包或酸奶)实际数据由 56 件物品组成,我需要检查与它交叉销售的所有物品. 所以我想要的结果必须看起来像 -

     Products sold with **bread**           Products sold with **Yoghurt**  

     yoghurt         2                        bread   2
     egg             1                        egg     1
     cheese          1                       butter   1
     butter          1          

     .... and list goes on like this for say 52 different articles. 
Run Code Online (Sandbox Code Playgroud)

我已经尝试了几件事,但对于这个大数据集来说它太手动了。借助 library(data.table) 解决这个问题会很棒,如果没有,那也很好。非常感谢您提前。

r dplyr data.table

2
推荐指数
1
解决办法
77
查看次数

标签 统计

data.table ×1

dplyr ×1

r ×1