0

I have three vectors.

v1 <- c("A", "C", "D", "E")
v2 <- c("A", "E", "G")
v3 <- c("C", "E", "S", "T")

I want all possible combinations but keeping the order, this is, in position 1 there can only be elements of v1, in position 2 elements of v2 and in position 3 elements of v3.

Some examples would be:

AAT; AES

Some examples of what it cannot happen are:

SDA; GAT

Pexav01
  • 45
  • 5
  • 3
    `expand.grid(v1,v2,v3)` ? If so, a possible duplicate of https://stackoverflow.com/questions/18705153/generate-list-of-all-possible-combinations-of-elements-of-vector – thelatemail May 23 '22 at 22:48
  • I believe expand.grid() computes all possible combinations not taking into account the requesit of the order. – Pexav01 May 23 '22 at 23:06
  • 2
    `expand.grid` produces a result where only the `v1` values are in the first column, only the `v2` values are in the second column, etc, which seems to match your request. Try it: `all(c("AAT","AES") %in% do.call(paste0, expand.grid(v1,v2,v3)))` is `TRUE` while `any(c("SDA","GAT") %in% do.call(paste0, expand.grid(v1,v2,v3)))` is `FALSE`. – thelatemail May 23 '22 at 23:13

0 Answers0