I have the matrix
x=matrix(c(1,1,2,2,10,10,20,20,21,21,30,30,31,31,40,40,
101,103,102,103,111,112,120,121,120,121,130,131,130,131,140,141),16,2)
I want to repeat each two rows of x a given number of times, that is based on y=c(2,2,2,1,1,1,1,1).
I mean that the first two rows of x are repeated two times (y[1] is equal to 2), the next two rows of x are repeated two times (y[2] is equal to 2), and so on. The last two rows of x are repeated once since (y[8] is equal to 1) is equal to one.
I have tried with rep but it repeats each row, but not every two rows.
I do not want to use any package, just base. Also, I want to avoid any for loop.