Sunday, 29 October 2023

Write a script in R to create two vectors of different lengths and give these vectors as input to array and print Multiplication of those matrices.-Big Data slip24

 Write a script in R to create two vectors of different lengths and give these vectors as input to array and print Multiplication of those matrices.


# Create two vectors of different lengths

vector1 <- c(1, 2, 3)

vector2 <- c(4, 5)

 # Convert the vectors into matrices

matrix1 <- matrix(vector1, nrow = 1)

matrix2 <- matrix(vector2, ncol = 1)

# Multiply the matrices

result <- matrix1 %*% matrix2

# Print the result

print(result)