merging two lists in R (many-to-many relationship) -


i trying merge 2 lists in r. names of list should used perform join. here toy example:

> list1 <- list(a=c(1,2,3), b=c(2,4,5,6), c=c(1,3)) > list2 <- list(a=c(w,x), b=c(y,z)) 

the final merged list should this:

$w [1] 1 2 3 $x [1] 1 2 3 $y [1] 2 4 5 6 $z [1] 2 4 5 6 

the idea had far convert lists data frames, , use merge function. there simpler do?

thanks lot help.

hopefully want? in fact don't need list2 @ all. because lists vectors, can use named vector "lookup" values of list1 need, assign names new list

list1 <- list(a=c(1,2,3), b=c(2,4,5,6), c=c(1,3))  lookup <- c(w = "a",x = "a",y = "b",z = "b")  list2 <- list1[lookup]  names(list2) <- names(lookup)  list2 $w [1] 1 2 3  $x [1] 1 2 3  $y [1] 2 4 5 6  $z [1] 2 4 5 6 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -