[S] Summary of my "Transforming the structure of a data frame" Ques

HumboltA@kochind.com
Fri, 11 Sep 1998 08:57:53 -0500


Thanks to all who responded to my question. Jean Adams and Christian Keller
provided me with the simplest and most extensible solutions. The answers
I'll give are:
> NewDat <- data.frame(tapply(mydat$Yield, list(mydat$Year, mydat$County),
mean))
> NewDat <- data.frame(tapply(mydat$Yield, list(mydat$Year, mydat$County),
function(x) {x}))

My original question involved how I can change "mydat" to look like "newdat"
similar to what I've shown below. Both of the above commands accomplish
this. Of course, with replicate data within a county the results would be
different for the two syntax's shown above; but that just illustrates the
power of understanding the above tapply logic.

mydat newdat

Year County Yield Bu Sg Su
1 97 Bu 20 97 20 25 27
2 97 Sg 25 98 30 35 37
3 97 Su 27
4 98 Bu 30
5 98 Sg 35
6 98 Su 37

Allen Humbolt
Quantitative Analyst
Koch Industries, Inc.
HumboltA@kochind.com

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news