I have a matrix x:
x <- matrix(1:8, nrow = 2, ncol = 4, byrow = 2)
# [,1] [,2] [,3] [,4]
#[1,] 1 2 3 4
#[2,] 5 6 7 8
I want to get a new matrix y:
# [,1] [,2] [,3] [,4]
#[1,] 24 24 12 4
#[2,] 1680 336 56 8
The logic is (taking the 1st row for example):
y[1, 1] = prod(x[1, 1:4])
y[1, 2] = prod(x[1, 2:4])
y[1, 3] = prod(x[1, 3:4])
y[1, 4] = prod(x[1, 4:4])
I know the prod function works if I want to multiply the entire row, but I can't figure out how to do the sequential multiplication I mentioned above.