Apparently this question has been asked before here, thanks for the quick answer!
The following issue has been puzzling me lately and I hope someone can help me with this. When using apply, the dimensions of my matrix end up being switched. See example below:
> A = matrix(c(2, 4, 3, 1, 5, 7), nrow=2, ncol=3, byrow = TRUE)
> A
[,1] [,2] [,3]
[1,] 2 4 3
[2,] 1 5 7
> M = c(1, 2, 3)
> B = apply(A, 1, "*", M)
> B
[,1] [,2]
[1,] 2 1
[2,] 8 10
[3,] 9 21
I know this can easily be transposed, so that isn't the problem. But my question is, why does R do this?
Hope you can help me with this.