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

January Weiner january at uni-muenster.de
Wed Dec 14 17:09:10 CET 2005


Hi,

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

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

Day val1 val2
Tue 2    5
Wed 1    5
etc.
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

--
------------ January Weiner 3  ---------------------+---------------
Division of Bioinformatics, University of Muenster  |  Schloßplatz 4
(+49)(251)8321634                                   |  D48149 Münster
http://www.uni-muenster.de/Biologie.Botanik/ebb/    |  Germany




More information about the R-help mailing list