RE: [S] data frame manipulation

Ed Callahan (lists@envstat.com)
Wed, 8 Apr 1998 12:05:12 -0500


Paul

Try,

>attach(barley)
>tapply(yield, list(year, site), mean)

You'll get a matrix in the form you desire that you can coerce to a
dataframe if necessary.

Ed

-------------------------------------------------------------------
Edward Callahan
Environmental Statistics
callahan@envstat.com

PO Box 563
Fountain City, WI 54629
(608) 687-3205
(608) 687-3409 (fax)
-------------------------------------------------------------------

-----Original Message-----
From: owner-s-news@wubios.wustl.edu
[mailto:owner-s-news@wubios.wustl.edu]On Behalf Of Paul Schwarz
Sent: Wednesday, April 08, 1998 10:14 AM
To: s-news@utstat.toronto.edu
Subject: [S] data frame manipulation

I'm developing my data manipulation skills in S-PLUS, and I've encountered
the following problem. Using the "barley" data frame as an example, I'd
like to create a new data frame containing the year by site mean yields
where years are the rows and sites are the columns.

I know how to calculate the summary data using the aggregate function:

> aggregate( barley[,1], list(year,site), mean )

This creates a data frame that looks like the following:

Group.1 Group.2 x
1 1932 Grand Rapids 20.81000
2 1931 Grand Rapids 29.05334
3 1932 Duluth 25.70000
4 1931 Duluth 30.29333
5 1932 University Farm 29.50667
6 1931 University Farm 35.82667
.
.
.

What I want end up with, though, is something that looks like this:

Year 'Grand Rapids' 'Duluth' 'University Farm' ...
1931 29.05334 30.29333 35.82667 ...
1932 20.81000 25.70000 29.50667 ...

I'm not sure how to create this last data frame. Any suggestions?

Thanks again!

-Paul
Paul.Schwarz@Cornell.EDU

P.S. Until I am re-subscribed to s-news, would you kindly cc: any
responses directly to me please?

-----------------------------------------------------------------------
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

-----------------------------------------------------------------------
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