[R] Aggregation and the meaning of class

From: Chip Barnaby <cbarnaby_at_wrightsoft.com>
Date: Fri, 30 May 2008 10:00:50 -0400

Dear R-ers,

My aggregation saga continues.

Using the following sequence, I can calculate any statistic for row groups and merge the result back to all associated rows ...

> WM = by( D60, D60[ "KeyProfA"], FUN=function(x) weighted.mean( x$IAC, x$Wt))

> D60$IAC.WM = as.numeric( WM[ D60$KeyProfA])

> class( WM)

[1] "by"

Questions ...

  1. Is this a reasonable way to obtain the desired result?
  2. What can one glean by knowing the class of WM ("by")? It appears to me that class is a pretty shallow attribute in R ... just an associated string that selects among methods in some contexts. Is that really all there is to it? Is there a way to discover what generic methods are aware of a given class? In other words, who cares if WM is a "by" ... what does that do for me?

In my traditional universe (C++) I can grep and discover what methods are virtual, who inherits from whom, etc. In R, the documentation appears silent on what is a "by" (correct me if I'm wrong). In addition, I have found no way to broadly search code to learn things. (Displaying single functions is useful but hardly broad.)

How does one learn R more efficiently than randomly discovering how to avoid error messages? (For example, I now know that a "by" cannot be coerced into a data.frame (although it seems to me that such a conversion could be usefully defined), so now I don't hit myself on the head with that particular hammer.)

Chip Barnaby

Chip Barnaby                   cbarnaby_at_wrightsoft.com
Vice President of Research
Wrightsoft Corp.               781-862-8719 x118 voice
131 Hartwell Ave               781-861-2058 fax
Lexington, MA 02421         www.wrightsoft.com

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 02 Jun 2008 - 05:12:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 02 Jun 2008 - 11:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive