Im trying to use expand grid in a function.
Suppose:
key <- c("a", "g", "t", "c")
asd <- c("A", "B", "D")
for(i in asd){
df = expand_grid(i = key)
}
What returns is:
# A tibble: 4 x 1
i
<chr>
1 a
2 g
3 t
4 c
What I want is:
# A tibble: 64 x 3
A B C
<chr> <chr> <chr>
1 a a a
2 a a g
3 a a t
4 a a c
5 a g a
6 a g g
7 a g t
8 a g c
9 a t a
10 a t g
# ... with 54 more rows
Which is for each element of my array to be the name and for the key to be the value.
In my minimum reproducible code to obtain this I should write:
df = expand_grid("A" = key,
"B" = key,
"C" = key)
But for the sake of what I want to do, which is a function, I want for "A" "B" "C"...."n" to be created based on another function. For the values of the returned array to be used as the names in expand grid.