按索引组合列表的元素 [英] Combining elements of list of lists by index

查看:62
本文介绍了按索引组合列表的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下列表列表:

lst = list(list(c(1,2), c(3,4)),list(c(5,6), c(7,8)),list(c(9,10), c(11,12)))

列表lst包含三个列表,每个列表包含两个向量作为元素.我想按索引组合基础列表的元素.换句话说,我想将列表1的向量1与列表2和列表3的向量合并,将列表1的向量2与列表2和列表3的向量合并,等等...

The list lst contains three lists, each list containing two vectors as elements. I would like to combine the elements of the underlying lists by index. In other words, I would like to merge vector 1 from list 1 with that of list 2 and list 3, and vector 2 from list 1 with that of list 2 and list 3, etc...

这是我想要实现的结果:

This is the result I am looking to achieve:

res = list(c(1,2,5,6,9,10), c(3,4,7,8,11,12))

我知道在两个单独的列表的情况下可以实现以下目的:

I know that this can be achieved as follows in case of two separate lists:

mapply(c, lst1, lst2)

但是,我不确定如何使用列表列表来复制相同的逻辑.

However, I am not sure how to replicate the same logic using a list of lists.

有什么有效的方法可以实现这一目标吗?请记住,实际上,lst是5000个列表的列表,每个基础列表都包含大量矢量.

Any efficient way to achieve that? Please keep in mind that in reality, lst is a list of 5000 lists, and each underlying list contains a large number of vectors.

谢谢!

推荐答案

您可以这样做:

do.call(Map, c(c, lst))

这篇关于按索引组合列表的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆