multiply two vectors - I want a scalar but I get a vector?
If what you essentially want is the sum of the products, then all you need is sum(a*a)
Two problems, multiplication in the wrong order, and the wrong multiply function.
> print(t(a)%*%a)
[,1]
[1,] 14
Equivalently:
> a=matrix(c(1,2,3),ncol=3)
> print (a %*% t(a))
[,1]
[1,] 14
Here a
is a matrix of 1 row, three columns.
See ?"%*%"
and ?"*"
You can simply do this,
> a <-c(1,2,3)
> b <-t(a)
> b %*% a
Here, %*%
acts as a matrix product.