Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (7.3k points)

I have two lists

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?

1 Answer

0 votes
by

You can use the mapply function to merge two lists if they have the same structure.i.e.,

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

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

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

Output:

$a

[1] 1 2

$b

[1] 2 3

$c

[1] 3 4

Related questions

0 votes
1 answer
0 votes
1 answer
+2 votes
3 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...