I'm a beginner with R. I wrote a double for loop for computing the dot product between each row of matrix x w.r.t. all the observations of sample X per time. I do not know how to store the results in a matrix having as columns the observations of sample X and as rows the rows of x. I hope someone can help me. Thanks in advance.
Here my code:
Dot.product <- function(x,X){
theta <- matrix(NA,nrow=nrow(x),ncol=nrow(X),byrow=T)
for(i in 1:nrow(X)){
for(j in 1:nrow(x)){
theta[i,j] <- acos((sum(x[j,]*X[i,]))/(sqrt
(sum(x[j,]*x[j,]))*sqrt(sum(t(X[i,])*X[i,]))))
}}
return(theta)}