rvector-multiplication

How R multiples vectors that are not compatible for multiplication


When I submit this code to R:

x <- c(1,2,4)
z <-  c(7,6,3)
a <- x * z

I get:

a
[1] 7 12 12

So R just multiples element by element. But the two vectors are not compatible for multiplication because the first one has three columns and the second one does not have three rows.

What is happening internally?


Solution

  • Please note that these are vectors; not tables.

    This means they can of course be multiplied with each other and would give the expected result through their inner product.