lucacerone
lucacerone

Reputation: 10119

Joining list of lists in R

I have the two lists (simple toy example)

X = list(A=list(a=1,b=2),B=list(a=10,b=20))

Y = list(A=list(c=3,d=4),B=list(c=30,d=40))

I would like to join them together in a list Z such that

Z$A = list(a=1,b=2,c=3,d=4)

and

Z$B = list(a=10,b=20,c=30,d=40)

Upvotes: 1

Views: 127

Answers (2)

PKumar
PKumar

Reputation: 11128

Use this if i understood you correctly:

After edit of question:

Z <- mapply(c, X, Y, SIMPLIFY=FALSE)

The above will give the same result as mentioned in your question

Upvotes: 2

Leo Schalkwyk
Leo Schalkwyk

Reputation: 21

Try this:

c(X,Y)  #gives the concatenation
list(X,Y) #gives a list of lists

Upvotes: 1

Related Questions