To calculate cross product in R, you can use cross() function from pracma library. The cross product is a binary operation on two vectors in three-dimensional space (R^3) and results in another vector that is perpendicular to the plane containing the input vectors.
The following method shows how you can do it with syntax.
Method: Use cross() Function
library(pracma)
cross(a,b)
The following example shows how to calculate cross product in R.
Calculate Cross Product Using cross() Function
Let’s see how we can calculate cross product in R using cross() function:
# Load library
library(pracma)
# Define vectors
a <-c(78,85,89)
b <-c(65,66,64)
# Calculate cross product
cross(a,b)
[1] -434 793 -377
The output shows cross product of vectors that we declare in the above code.