Tuesday, 10 October 2023

BigData-Slip28-Write an R program to convert a given matrix to a list and print list in ascending order.

 Slip28

Write an R program to convert a given matrix to a list and print list in ascending order.

 m <- matrix(1:9, nrow = 3)

 list_from_matrix <- matrix_to_list(m)

 # Print the list in ascending order

sorted_list <- sort(list_from_matrix)

print(sorted_list)

 list_from_matrix <- matrix_to_list(m)

 # Print the list in ascending order

sorted_list <- sort(list_from_matrix)

print(sorted_list)

 

Output

 

> m <- matrix(1:9, nrow = 3)

>

> list_from_matrix <- matrix_to_list(m)

>

> # Print the list in ascending order

> sorted_list <- sort(list_from_matrix)

> print(sorted_list)

[1] 1 2 3 4 5 6 7 8 9

>

> list_from_matrix <- matrix_to_list(m)

>

> # Print the list in ascending order

> sorted_list <- sort(list_from_matrix)

> print(sorted_list)

[1] 1 2 3 4 5 6 7 8 9