In mathematics, the dot product or also known as the scalar product is an algebraic operation that takes two equal-length sequences of numbers and returns a single number. Let us given two vectors A and B, and we have to find the dot product of two vectors.
i: the unit vector along the x directions
j: the unit vector along the y directions
k: the unit vector along the z directions
Then the dot product is calculated as:
Given two vectors A and B as,
A = 3i + 5j + 4k,
B = 2i + 7j + 5k
Dot Product = 3 * 2 + 5 * 7 + 4 * 5 = 6 + 35 + 20 + 61
Computing Dot Product in R
R language provides a very efficient method to calculate the dot product of two vectors. By using dot() method which is available in the geometry library one can do so.
Syntax: dot(x, y, d = NULL)
x: Matrix of vectors
y: Matrix of vectors
d: Dimension along which to calculate the dot product
Return: Vector with length of dth dimension
In this following example let’s take two 2D arrays and calculate the dot product of these two. To create a 2D array in R please refer Multidimensional Array in R.
 10 9