[R] How to calculate the product of every two elements in two lists?

Joshua Wiley jwiley.psych at gmail.com
Mon Jun 13 16:20:13 CEST 2011


Okay, what about this:

## use expand.grid() to create a data frame of all combinations
## of the element numbers of zz and tt
index <- expand.grid(seq_along(zz), seq_along(tt))
index

## use the index to select the element of zz and tt and find their product
mapply(`*`, zz[index[, 1]], tt[index[, 2]])

HTH,

Josh

On Mon, Jun 13, 2011 at 7:12 AM, Carla Moreira <carlamgmm at gmail.com> wrote:
> Thank you very much.
>
> I want each element of zz by each element of tt (i.e., every
> possible 2-way combination).
>
>
> Carla



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list