[R] class and method

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Apr 13 05:26:44 CEST 2007

On Thu, 12 Apr 2007, jiho.han wrote:

> Hi, R-experts
> I defined a new class of object, called "alpha", which is basically a
> data.frame. And (I think) I know how to create a method for "alpha", such as
> "summary.alpha", "plot.alpha". The problem is, when I try to access "alpha"
> object by usual data.frame method, it won't.
> For example, suppose X is an object of class "alpha". Then, the commands
> such as dim(X), X[1,1], none of these works.
> I want to know how to define a class so that when there is appropriate
> methods use it, but when there's not use the predetermined method for
> underlying object. Any comments would be appreciated. Thanks-

class(X) <- c("alpha", "data.frame")

is I think what you want.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list