Q:

Write a R program to convert a given matrix to a list of column-vectors

0

Write a R program to convert a given matrix to a list of column-vectors.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

x = matrix(1:12, ncol=3)
print("Original matrix:")
print(x)
print("list from the said matrix:")
l =  split(x, rep(1:ncol(x), each = nrow(x)))
print(l)

Sample Output:

[1] "Original matrix:"
     [,1] [,2] [,3]
[1,]    1    5    9
[2,]    2    6   10
[3,]    3    7   11
[4,]    4    8   12
[1] "list from the said matrix:"
$`1`
[1] 1 2 3 4

$`2`
[1] 5 6 7 8

$`3`
[1]  9 10 11 12

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now