There are two vectors x: 1 3 5 7
& y: 2 4 6 8
. I used the function outer to build a matrix(4*4)
from all possible combinations between the elements in both vectors like:
x<-c(1,3,5,7)
y<-c(2,4,6,8)
comb<-outer(x,y, paste, sep=".")
> comb
[,1] [,2] [,3] [,4]
[1,] "1.2" "1.4" "1.6" "1.8"
[2,] "3.2" "3.4" "3.6" "3.8"
[3,] "5.2" "5.4" "5.6" "5.8"
[4,] "7.2" "7.4" "7.6" "7.8"
I don't now if it is possible to index one element in a cell, for example if there is a way to call only the element 2
from first cell comb[1,1]
Is there something like comb[[1,1]][2]=2
"I know it is not working"
And if this is not possible in this way, is there another way construct a matrix from the combinations and to be able after that to call and index each element alone??
By the way: I work on graphs and vectors of vertices so if there are other functions like this one for graphs please direct me.
Thanks