[R] overloading "[" and "[<-" using S3 classes

Gabor Grothendieck ggrothendieck at gmail.com
Sat Oct 30 15:25:47 CEST 2010


On Sat, Oct 30, 2010 at 9:03 AM, Mark Heckmann <mark.heckmann at gmx.de> wrote:
> How can I overload the "[" and "[<-" operators using S3 classes?
> Something like '['.{class} did not work or at least I do not know how to define it properly.
>
>
> For S4 it is straightforward:
>
> setMethod("[", signature(x = "myClass", i = "numeric"),
>        function (x, i, j, ..., drop){
>                ... some operations
> })
>
> How to do the same for S3?

Check out some examples by entering this into R:

methods("[") # lists [ methods
`[.data.frame`
stats:::`[.ts`



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list