Saturday, 17 August 2013

Applying outer to columns within a matrix

Applying outer to columns within a matrix

I have two matrices: x
A B C
2 3 4
3 4 5
and y
D E
1 2
3 2
How can I subtract the a combination of elements within columns? Giving me
the following result:
AD AE BD BE CD CE
1 0 2 1 3 2
0 1 1 2 2 3
I have tried applying outer, but can't make it work with matrices. Would
vectorizing a function be a solution? I have tried the code below, but it
doesn't seem to work.
vecfun= Vectorize(fun)
fun=function(a,b)(a-b)
outer(x,y, vecfun)
Thanks in advance for any advice.

No comments:

Post a Comment