I was wondering how if I could find & remove the common elements in i+1
-th vector of a list (in base R
)?
For example:
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)])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.