Output
[1] 2 6 12
Let's see the explanation of how it has multiplied one vector to another vector.
They are multiplied to each other by their position i.e., index. We can see that the element of the first vector which was at index 1 is multiplied by the element of the second vector which was at the index of 1. In the same way, the elements of the first vector at the index 2 and 3 were multiplied to the element of the second vector which was at the index 2 and 3 respectively.
Remember that index of the vector in R starts with 1, not 0.
This concept is simplified in the below image.
Multiplication Rule - Commutative Property of Multiplication
Vector multiplication in R follows commutative property of multiplication according to which when two numbers are multiplied with each other, then the result remains the same regardless of their order or sequence. We can say it by example 3 * 4 = 4 * 3 simply.
Let's see this in R by executing the above code by changing the sequence only.