[R] as.list.matrix

Kjetil Brinchmann Halvorsen kjetil at acelerate.com
Fri Oct 29 03:16:03 CEST 2004

I found the need of converting a matrix into a list of its columns
(for use with do.call), and was surprised there was no method
as.list.matrix, it could easily be a part of as.list default

I wrote

my.as.list.matrix <- function(mat) {
       if(!is.matrix(mat))stop("Argument must be a matrix")
       n <- NCOL(mat)
       res <- vector(mode="list", length=n)
       for (i in seq(along=res))
         res[[i]] <- mat[,i]

but still think there must be some in-built function doing this!

By the way, my use is

        xlab="", ylab="")))

there shoud be an easier way for such a daily task?



Kjetil Halvorsen.

Peace is the most effective weapon of mass construction.
               --  Mahdi Elmandjra

More information about the R-help mailing list