Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joining Lists in R

Tags:

list

r

I am trying to join two lists in R, but I really don't know how to do it. I need a way to join the to lists by adding only the elements that have a different name from the ones to the first list, say:

list1=list('a'=1,'b'=2,'c'=3,'d'=4,'e'=5);
list2=list('b'=10,'c'=100,'e'=98);
list3=OpErAtIoN(list1,list2)

And one gets that list3 is list('a'=1,'b'=10,'c'=100,'d'=4,'e'=98)

Do you know any way to do it? Thank you!

like image 678
Francisco Martínez Avatar asked Feb 04 '14 16:02

Francisco Martínez


People also ask

How do you add two lists in R?

R provided two inbuilt functions named c() and append() to combine two or more lists. c() function in R language accepts two or more lists as parameters and returns another list with the elements of both the lists. Example 1: R.

How do I add one list to another list in R?

To append an element in the R List, use the append() function. You can use the concatenate approach to add components to a list. While concatenate does a great job of adding elements to the R list, the append() function operates faster.

How do I combine a list of Dataframes in R?

To combine data frames stored in a list in R, we can use full_join function of dplyr package inside Reduce function.

How do I extract an element from a list in R?

The [[ operator can be used to extract single elements from a list. Here we extract the first element of the list. The [[ operator can also use named indices so that you don't have to remember the exact ordering of every element of the list. You can also use the $ operator to extract elements by name.


1 Answers

This gives the same result as your example:

modifyList(list1, list2)
like image 89
G. Grothendieck Avatar answered Oct 16 '22 15:10

G. Grothendieck