I am trying to create a unique combination of all elements from two vectors of different sizes in R.
For example, the first vector
> a <- c("ABC", "DEF", "GHI")
and the second is the dates currently stored as
> b <- c("2012-05-01", "2012-05-02", "2012-05-03", "2012-05-04", "2012-05-05")
I need to create a data frame with two columns like this
> data ab 1 ABC 2012-05-01 2 ABC 2012-05-02 3 ABC 2012-05-03 4 ABC 2012-05-04 5 ABC 2012-05-05 6 DEF 2012-05-01 7 DEF 2012-05-02 8 DEF 2012-05-03 9 DEF 2012-05-04 10 DEF 2012-05-05 11 GHI 2012-05-01 12 GHI 2012-05-02 13 GHI 2012-05-03 14 GHI 2012-05-04 15 GHI 2012-05-05
So, basically, I'm looking for a unique combination, considering all the elements of one vector (a), compared with all the elements of the second vector (b).
An ideal solution will generalize to a larger number of input vectors.
See also:
How to create a combination matrix
r r-faq
Godel Jul 09 '12 at 2:10 2012-07-09 02:10
source share