From ggrothendieck at myway.com  Fri Dec 19 21:03:44 2003
From: ggrothendieck at myway.com (Gabor Grothendieck)
Date: Fri Dec 19 21:02:41 2003
Subject: [Rd] t.data.frame
Message-ID: <20031219200344.6E6A839AE@mprdmxin.myway.com>


I would like to propose that t.data.frame be changed using the
source code below.

Right now t.data.frame coerces the data frame to a matrix and then
transposes the matrix.

I would like to propose that t.data.frame be changed to:

	t.data.frame <- function( df ) { 
		ll <- NULL
		for( i in 1:nrow(df) ) ll <- append( ll, list(df[i,]) )
		ll 
	}

That would allow one to iterate, using for, over the rows of a 
data frame just as easily as the columns without using indices:

	# iterate over columns of df
	for( v in df ) ... statements involving v ...

	# iterate over rows of df
	for( u in t(df) ) ... statements involving u ...

This is less efficient than 

	for( i in 1:nrows(df) ) ... statements involving df[i,] ...

but its simpler and reduction in complexity can be more important
than raw efficiency.   Furthermore, it does not preclude the use
of the index form just cited.

One could still get the old behavior of t like this:

	t(as.matrix(df))


[Rd] t.data.frame
Gabor Grothendieck