[英]Removing the common elements in i+1 th vector of a list in base R
我想知道如何找到并删除列表的第i+1
个向量中的公共元素(在基数R
)?
例如:
x = list(a = 1:5, b = 3:7, c = 6:9) # Initial list
common <- # your solution # ? find common values
for(i in 1:length(x)) {
# your solution: ?create `b` removing common elements with `a`
# your solution: ?create `c` removing common elements with `b`
}
当我们比较相邻元素时,在删除last
和first
元素的list
last
使用setdiff
并更新“x” list
x[-1] <- Map(setdiff, x[-1], x[-length(x)])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.