[R] Creating a list from all combinations of two lists
Jim Lemon
jim at bitwrit.com.au
Tue Nov 22 07:52:22 CET 2011
On 11/22/2011 06:31 AM, Jonathan Greenberg wrote:
> R-helpers:
>
> Say I have two lists of arbitrary elements, e.g.:
>
> list1=list(c(1:3),"R is fun!",c(3:6))
>
> list2=list(c(10:5),c(5:3),c(13,5),"I am so confused")
>
>
> I would like to produce a single new list that is composed of all
> combinations of the "top level" of list1 and list2, e.g.:
>
> listcombo=list(list(list1[[1]],list2[[1]]),list(list1[[1]],list2[[2]]
> ),...,list(list1[[length(list1)]],list2[[length(list2]]))
>
> What is the most efficient way to do this? Thanks!
>
Hi Jonathan,
The makeIntersectList function (plotrix) does this for the attribute
labels that represent the top level sets. However, it assumes that the
attribute labels are character variables. You may be able to generalize
the code to handle arbitrary objects.
Jim
More information about the R-help
mailing list