Write a R program to convert a given matrix to a list of column-vectors.
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
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
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 12need an explanation for this answer? contact us directly to get an explanation for this answer