# [R] match lists

bogdan romocea br44114 at gmail.com
Mon Oct 30 22:53:51 CET 2006

```What is it that you don't know how to do? Loop over the matrices from
the 2 lists and merge them two by two, for example
AB <- list() ; id <- 1
for (i in 1:length(A)) for (j in 1:length(B)) {
AB[[id]] <- merge(A[[i]],B[[j]],...)
id <- id + 1
}
To better keep track of who's who, you may want to set up A and B as
named lists, and replace id with
paste(names(A)[i],names(B)[j]).

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Heymans, MW
> Sent: Sunday, October 29, 2006 6:35 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] match lists
>
> Dear list,
>
>
> I have list A that contains two matrix elements:
> [[1]]
>      a b
> [1,] 2 1
> [2,] 3 2
> [3,] 3 2
> [[2]]
>      c d
> [1,] 3 5
> [2,] 3 1
> [3,] 2 3
>
> and list B, that also contains 2 matrices:
> [[1]]
>      e   f   g
> [1,] 1  20  30
> [2,] 2  40  50
> [3,] 3  60  70
> [4,] 4  80  90
> [5,] 5 100 110
> [[2]]
>      h  i  j
> [1,] 1 10 20
> [2,] 2 20 30
> [3,] 3 30 40
> [4,] 4 40 50
> [5,] 5 50 60
>
> Now I want to match each column of list A with each row of
> list B in such a way that element 1 of list A corresponds to
> element 1 of list B (and element 2 of A with 2 of B).
> So, in total there will be 4 new matrices, 1 for each column
> of list A. For example, for column a of list A the new matrix will be:
>
> 2  40  50
> 3  60  70
> 3  60  70
>
> thanks,
> Martijn
> VUmc
> Amsterdam
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help