[R] dataframe to list conversion

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Mon Jul 27 19:50:50 CEST 2009


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,sum)
>     return(s)    
> }
> 
> I wish to use the same code up until the return(s) that I have listed above. 
> The problem is that s, I believe, is a data frame (looks like this:)
> 
> $X1
> [1] 148
> 
> $X2
> [1] 156
> 
> $X3
> [1] 164
> 
> $X4
> [1] 172
> 
> $X5
> [1] 180
> 
> I would like a vector with these values (148,156,etc).  How may I do this? 
> tia!

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014




More information about the R-help mailing list