How can I multiply columns by columns from different matrix in R?

Viewed 35

guys: I have two matrix as following:

d <- cbind(c(1,2,3,4),c(1,1,1,1),c(1,2,4,8))
v <- cbind(c(2,2,2,2),c(3,3,3,3))

But I want to get a matrix consisted of divj as following:

    d1v1 d1v2 d2v1 d2v2 d3v1 d3v2
    2     3    2    3    2    3
    4     6    2    3    4    6
    6     9    2    3    8    12
    8    12    2    3    16   24

This is an example of my question,I wonder if you can tell me how to write codes to solve this question.Many thanks.

1 Answers
matrix(apply(v,2,function(x){x*d}),4,6)
Related