在R中合并两个列表 [英] Merge Two Lists in R

查看:997
本文介绍了在R中合并两个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表

first = list(a = 1, b = 2, c = 3)
second = list(a = 2, b = 3, c = 4)

这两个列表,所以最终的产品是

I want to merge these two lists so the final product is

$a
[1] 1 2

$b
[1] 2 3

$c
[1] 3 4

有没有一个简单的功能来做到这一点?谢谢!

Is there a simple function to do this? Thanks!

推荐答案

如果列表总是具有相同的结构,如在示例中,那么一个更简单的解决方案是

If lists always have the same structure, as in the example, then a simpler solution is

mapply(c, first, second, SIMPLIFY=FALSE)

这篇关于在R中合并两个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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