Matrix dot-product in R -


i tring figure out how dot product.

b = matrix(1:70, ncol=7) g= matrix(1:48, ncol=6) resulta = matrix(0,6,7) (c in 1:ncol(b)){   (i in 1:ncol(g)){     resulta[i,c] <- sum((g[,i]) * (b[,c]))   } } 

warning messages:

1: in (g[, i]) * (b[, c]) :   longer object length not multiple of shorter object length 2: in (g[, i]) * (b[, c]) :   longer object length not multiple of shorter object length 

...........................total 42 alike messages

whenever multiply matrices, have make sure dimensions such #columns of first matrix same #rows of second i.e. if first matrix a x b, second matrix has b x c (c , may or may not equal) resultant matrix a x c.

in case, matrix b 70 x 7 meaning matrix g should 7 x something matrix. in other words, matrix g should have 7 rows.

once have fixed dimensions, try quick matrix multiplication:
resulta <- b %*% g
resulta


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -