Sometimes I just want to feed indices or labels into a map* type function, especially in problems where the easiest solution is to enumerate all possible combinations. So, I write an expression like this
x = expand.grid(paste0("A", 1:10), paste0("B", 1:10))
Var1 Var2
1 A1 B1
2 A2 B1
3 A3 B1
4 A4 B1
5 A5 B1
6 A6 B1
Now, now I want to convert each row to a list with an ugly hack like
data.frame(t(x))
Or do something like this, which is annoying since the output is a nested list, and requires another lapply
to fix.
apply(x, 1, list)
then lapply(.Last.value, unlist)
There has to be a more elegant way of doing this right?