[R] Looking for a sort of tapply() to data frames

From: January Weiner <january_at_uni-muenster.de>
Date: Thu 15 Dec 2005 - 03:09:10 EST


I read about the by() function, but it does not seem to do the job I need. Here is the problem:

Say - I have a data frame, with three columns. The first one contains strings that describe the data points, with repeats (for example, days of a week). The other two contain numbers. Something like that:

Day val1 val2
Tue 1 2
Tue 2 8
Tue 3 5
Wed 1 2
Wed 1 8

Now I would like to have a data frame with averages for each week:

Day val1 val2
Tue 2 5
Wed 1 5
I now I can do tapply(DF$val2, DF$days, mean) to get the means for val2. But I would like to have a data frame as result (as in reality I have many more columns).

Further question: where can I find a good, advanced introduction to R data types? R's help() function just kills my brain, and the tutorials are very limited.

My kind regards,

January Weiner


R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Dec 15 03:17:08 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:39 EST