[英]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.