[R] Row-wisely converting a data frame into a list

David Winsemius dwinsemius at comcast.net
Tue Mar 2 14:45:08 CET 2010


On Mar 2, 2010, at 8:11 AM, Sebastian Bauer wrote:

> Hello,
>
> is there an elegant way, how I can convert each row of a data frame  
> into distinct elements of a list?

split(dfrm, rownames(dfrm))

>
> In essence, what I'm looking for is something like
>
> rows.to.lists <- function( df ) {
> 	ll <- NULL
> 	for( i in 1:nrow(df) )
> 		ll <- append( ll, list(df[i,]) )
> 	return (ll)
> }
>
> but more done more efficiently (the data frame may contain ten- 
> thousands of rows). I thought about using apply() but this function  
> always returns a matrix.
>
> Thanks in advance!
>
> Bye,
> Sebastian
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list