我必须把列表中的所有元素互相比较,狗对cat ,狗对老鼠,cat 对老鼠.
animals <- list(
dog = data.frame(
col_1 = sample(c(100:200), size = 10, replace = TRUE),
col_2 = sample(c(100:200), size = 10, replace = TRUE),
col_3 = sample(c(100:200), size = 10, replace = TRUE),
col_4 = sample(c(100:200), size = 10, replace = TRUE)
),
cat = data.frame(
col_1 = sample(c(100:200), size = 10, replace = TRUE),
col_2 = sample(c(100:200), size = 10, replace = TRUE),
col_3 = sample(c(100:200), size = 10, replace = TRUE),
col_4 = sample(c(100:200), size = 10, replace = TRUE)
),
mouse = data.frame(
col_1 = sample(c(100:200), size = 10, replace = TRUE),
col_2 = sample(c(100:200), size = 10, replace = TRUE),
col_3 = sample(c(100:200), size = 10, replace = TRUE),
col_4 = sample(c(100:200), size = 10, replace = TRUE)
)
)
我想比较一下上面两个字的每一个组合.比较的类型并不重要——只要这样说,这可以通过generic_function()
来完成:
generic_function(animals$dog[, c("col_1", "col_2")],
animals$cat[, c("col_1", "col_2")])
由于有很多数据要比较,我想使用lapply
函数,但我不知道如何创建列表的各个级别之间的交集.你能帮我吗?