[R] as.list.matrix

Peter Alspach PAlspach at hortresearch.co.nz
Fri Oct 29 04:08:21 CEST 2004


Kjetil

Isn't a data.frame as special type of list, and thus one could use
as.data.frame?

Peter Alspach


>>> Kjetil Brinchmann Halvorsen <kjetil at acelerate.com> 29/10/04
14:16:03 >>>
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]
       res
}

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

By the way, my use is

 with(VRS,do.call("scatter.smooth",
    c(my.as.list.matrix(na.omit(cbind(Tmed, 
resid(VRS.mod1,type="response")))),
        xlab="", ylab="")))

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

Kjetil

-- 

Kjetil Halvorsen.

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

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________________

The contents of this e-mail are privileged and/or confidenti...{{dropped}}




More information about the R-help mailing list