对比数据集R中 [英] Compare datasets in R
本文介绍了对比数据集R中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收集了一组事务格式的CSV文件:
I have gathered a set of transactions in a CSV file of the format:
{Pierre, lait, oeuf, beurre, pain}
{Paul, mange du pain,jambon, lait}
{Jacques, oeuf, va chez la crémière, pain, voiture}
我打算做一个简单的关联规则分析,但首先我要排除每个交易项目不属于 ReferenceSet = {牛乳,OEUF,Beurre黄油,疼痛}
。
因此,我的结果数据是,在我的例子:
Thus my resulting dataset would be, in my example :
{Pierre, lait, oeuf, beurre, pain}
{Paul,lait}
{Jacques, oeuf, pain,}
我敢肯定,这是很简单的,但很想读的建议/答案,帮助我一下。
I'm sure this is quite simple, but would love to read suggestions/answers to help me a bit.
推荐答案
另一个答案引用%在%
,但在这种情况下,相交
甚至更加得心应手(你可能想看看匹配
,太 - 但我认为这是在同一个地方记录为%在%
) - 以 lapply
和相交
我们可以把答案为一-liner:
Another answer references %in%
, but in this case intersect
is even handier (you may want to look at match
, too -- but I think it's documented in the same place as %in%
) -- with lapply
and intersect
we can make the answer into a one-liner:
数据:
> L <- list(pierre=c("lait","oeuf","beurre","pain") ,
+ paul=c("mange du pain", "jambon", "lait"),
+ jacques=c("oeuf","va chez la crémière", "pain", "voiture"))
> reference <- c("lait", "oeuf", "beurre", "pain")
答:
> lapply(L,intersect,reference)
$pierre
[1] "lait" "oeuf" "beurre" "pain"
$paul
[1] "lait"
$jacques
[1] "oeuf" "pain"
这篇关于对比数据集R中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文