Skip to content

Strange Matrix Multiplication Behaviour

1 message · Liaw, Andy

#
What you need to realize is that R does vectorized computation in `Fortran'
order.  Here's a perhaps more illuminating example:
[1] 1 2 1 2 1 2
V1 V2 V3 V4 V5 V6
1  1  3  5  7  9 11
2  2  4  6  8 10 12
V1 V2 V3 V4 V5 V6
1  1  6  5 14  9 22
V1 V2 V3 V4 V5 V6
1  1  3  5  7  9 11

When you do (tr * ex1)[1,], R multiplies tr and ex1 element-by-element,
stacking _columns_ of ex1 to match tr, and recyle the elements of tr to
match the length of the `stacked' ex1.

Andy