7

I have two vectors like this:

f1=c('a','b','c','d')
e1=c('e','f','g')

There is 4^3 different permutations of them. I need to create all of possible permutations of them in R softeware.for example;

(1):
a e
a f
a g
(2):
a e
a f
b g
...

Moreover, my real data are very huge and I need speed codes.

Kazimierz Jawor
  • 18,861
  • 7
  • 35
  • 55
user2877990
  • 71
  • 1
  • 2
  • 2
    This is a many times over duplicate and I don't think the search terms are that obtuse. Did you really search before you posted? – Simon O'Hanlon Nov 22 '13 at 16:59
  • Can't post an answer, but see my answer [here](https://stackoverflow.com/a/56154619/188963) that I think is much better suited to this problem. – abalter May 15 '19 at 17:21

1 Answers1

12

It sounds like you are looking for expand.grid.

> expand.grid(f1, e1)
   Var1 Var2
1     a    e
2     b    e
3     c    e
4     d    e
5     a    f
6     b    f
7     c    f
8     d    f
9     a    g
10    b    g
11    c    g
12    d    g

I don't know what "speed codes" are, so I'm not sure I can help from that aspect.

A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485