【问题标题】:Set operations on list of sets in R using sets package使用 sets 包对 R 中的集合列表进行集合操作
【发布时间】:2019-01-08 08:18:54
【问题描述】:

我正在使用sets package in R。现在,我有一个集合列表,我想在列表上执行集合操作而不必循环。就像,我可以用可变数量的参数做set_intersection

set_intersection(set(1,2), set(2,3), set(4,5), set(5,6)..)

但是如果我有一个类似的列表呢

ls = list(set(1,2), set(2,3), set(4,5), set(5,6))

如何取 ls 中包含的所有集合的交集?尝试用谷歌搜索,但找不到太多。

【问题讨论】:

  • 试试Reduce(set_intersection, ls)

标签: r set set-operations


【解决方案1】:

我们可以使用Reduceset_intersection

library(sets)
Reduce(set_intersection, ls)

do.call

do.call(set_intersection, ls)

注意:最好不要用函数名来命名对象(ls 是一个函数)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 2020-04-21
    • 2016-05-07
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 1970-01-01
    相关资源
    最近更新 更多