1

I'd like to obtain the vertices of d-dimensional hypercube without to use packages. In instance, a hypercube of dimension d = 4, the output desired is

      Var1 Var2 Var3 Var4
 [1,]    0    0    0    0
 [2,]    1    0    0    0
 [3,]    0    1    0    0
 [4,]    1    1    0    0
 [5,]    0    0    1    0
 [6,]    1    0    1    0
 [7,]    0    1    1    0
 [8,]    1    1    1    0
 [9,]    0    0    0    1
[10,]    1    0    0    1
[11,]    0    1    0    1
[12,]    1    1    0    1
[13,]    0    0    1    1
[14,]    1    0    1    1
[15,]    0    1    1    1
[16,]    1    1    1    1

I thinked to make a function given by

cube <- function(d){
  res <- diag(d)
  #res repeated d = 4 
  replicas <- unique(expand.grid(res, res, res, res))
  replicas
}

But it clearify that this isn't optimized.

Wagner Jorge
  • 430
  • 3
  • 15

0 Answers0