Re: [R] dataframe to list conversion

2009-07-27 Thread Jorge Ivan Velez
Dear voidobscura, Try also Csum <- function(x) apply(x, 2, sum) Csum(m) HTH, Jorge On Mon, Jul 27, 2009 at 11:03 AM, voidobscura <> wrote: > > Hi all, I have been experimenting with writing my own matrix column sum > function. I want it to return a list. > > csum<-function(m) > { >a = da

Re: [R] dataframe to list conversion

2009-07-27 Thread Bill.Venables
All you need is csum <- function(m) sapply(m, sum) (in which case making csum a function does not achieve very much). If for some reason you want to hang on to your code and just modify the last line (though I cannot think why, but still...) you could do csum <- function(m) { a <- data.fr

Re: [R] dataframe to list conversion

2009-07-27 Thread Jorge Ivan Velez
Hi voidobscura, Try either csum2 <- function(m){ a = data.frame(m) s = lapply(a,sum) do.call(c, s) } or colSums(m) See ?do.call and ?colSums for more details. HTH, Jorge On Mon, Jul 27, 2009 at 11:03 AM, voidobscura wrote: > > Hi all, I have been experimenting with writing my own

Re: [R] dataframe to list conversion

2009-07-27 Thread Dimitris Rizopoulos
have a look at ?unlist(); you can also use sapply() in this case instead of lapply(). Best, Dimitris voidobscura wrote: Hi all, I have been experimenting with writing my own matrix column sum function. I want it to return a list. csum<-function(m) { a = data.frame(m) s = lapply(a,s