我可以在一个小的列表中从每个数据中找到共享元素。一个简化的示例在这里:
WHEN
existsNode(DL_XML, '/DEAL/LOAN/AFFORDABLE_LENDING/LoanGovernmentBondIndicator') != 1
THEN
XMLQuery('copy $tmp := $oldDealXml modify insert node $mrbFlagXMLNode into $tmp/DEAL/LOAN/AFFORDABLE_LENDING
但是实际工作中的问题是:列表确实很大,说它包含100个数据,那么这种方法不再有效,并且可能会引入错误。有没有一种方法可以避免列出所有data_1 <- c("A","B")
data_2 <- c("A","B","C")
data_3 <- c("A","B","C","D")
data_4 <- c("A","B","F","N")
list.a <- list(data_1,data_2,data_3,data_4)
# find common elements
shared <- Reduce(intersect, list(list.a[[1]], list.a[[2]], list.a[[3]]), list.a[[4]]))
# outputs
print(shared)
[1] "A" "B"
?简洁的东西。
答案 0 :(得分:1)
只需使用您的列表,而不要列出其子元素。
(shared <- Reduce(intersect, list.a))
# [1] "A" "B"
答案 1 :(得分:0)
这是reduce
library(purrr)
library(dplyr)
list.a %>%
reduce(intersect)