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

Sebastian Bauer Sebastian.Bauer at charite.de
Tue Mar 2 14:11:38 CET 2010


Hello,

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

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



More information about the R-help mailing list