我有以下两个清单:
First list:
[[1]]
[1] "ab" "iew" "rer" "fdd"
[[2]]
[1] "ff" "de
[[3]]
[1] "cc"
Second list:
[[1]]
[1] "iew" "vfr"
[[2]]
[1] "ff" "cdc"
[[3]]
[1] "vf" "cde"
我的目标是比较这两个多维列表,结果将是:
[[1]]
[1] FALSE TRUE FALSE FALSE
[[2]]
[1] TRUE FALSE
[[3]]
[1] FALSE
预先形成此intersect()函数的最佳矢量化方法是什么?
答案 0 :(得分:5)
以下是使用mapply
> mapply("%in%", Firt.list, Second.list)
[[1]]
[1] FALSE TRUE FALSE FALSE
[[2]]
[1] TRUE FALSE
[[3]]
[1] FALSE
First.list
和Second.list
的位置:
Firt.list <- list(c("ab", "iew", "rer", "fdd" ), c("ff", "de"), c("cc"))
Second.list <- list(c("iew", "vfr"), c("ff", "cdc"), c("vf", "cde"))
如果您想知道哪些值是列表的intersect
,请尝试使用
> mapply("intersect", Firt.list, Second.list)
[[1]]
[1] "iew"
[[2]]
[1] "ff"
[[3]]
character(0)