簡體   English   中英

刪除基數 R 中列表的第 i+1 個向量中的公共元素

[英]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`
}

當我們比較相鄰元素時,在刪除lastfirst元素的list last使用setdiff並更新“x” list

x[-1] <- Map(setdiff, x[-1], x[-length(x)])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM