合并相交列表元素
我有一个r
integer
vector
s的列表,某些元素是冗余的,而其他元素相互相交:
ll <- list(c(1,4), c(5,7,3,9), c(5,3,7,9), c(2,7,10), 8, 6)
Integer
vector
元素中的s只是索引而不是范围,列表中元素的顺序是任意的。
我正在寻找一个将返回list
的函数,该函数将合并ll
的相交元素并删除冗余。
对于示例ll
,此功能将返回:
list(c(1,4), c(2,3,5,7,9,10), 6, 8)
有什么想法吗?
不幸的是,@Alexis_laz在这篇文章无法解决我的问题,因为它假定列表已排序,这不是我的情况。
例如,如果我更改ll
的元素的顺序:
ll <- list(c(2,7,10), c(1,4), c(5,7,3,9), 8, 6, c(5,3,7,9))
@Alexis_laz的解决方案的矢量元素则无法保持。
I have a list of R
integer
vector
s which some elements are redundant and others intersect each other:
ll <- list(c(1,4), c(5,7,3,9), c(5,3,7,9), c(2,7,10), 8, 6)
The integer
s in the vector
elements are just indices and not ranges, and the order of the elements in the list is arbitrary.
I'm looking for a function that'll return a list
that'll merge ll
's intersecting elements and remove the redundancy.
For the example ll
above this function will return:
list(c(1,4), c(2,3,5,7,9,10), 6, 8)
Any idea?
Unfortunately, the solution offered by @alexis_laz in this post doesn't solve my problem because it assumes that the list is ordered, which is not my case.
For example, if I change the order of ll
's elements:
ll <- list(c(2,7,10), c(1,4), c(5,7,3,9), 8, 6, c(5,3,7,9))
@alexis_laz's solution doesn't hold.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很混乱,但我为您的情况做出了工作。
It's pretty messy but it my works for your case.