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 second row of second matrix of the array.-Big Data Slip23

 

Write a script in R to create two vectors of different lengths and give these vectors as input to array and print second row of second matrix of the array.

 

# Create two vectors of different lengths

vector1 <- c(1, 2, 3)

vector2 <- c(4, 5)

 

# Create an array from the two vectors

my_array <- array(c(vector1, vector2), dim = c(2, max(length(vector1), length(vector2)))

 

# Print the second row of the second matrix in the array

second_matrix <- my_array[,,2]

second_row <- second_matrix[2,]

 

print(second_row))