Skip to content

combining tables

2 messages · robin hankin, Gabor Grothendieck

#
On 19 Jun 2006, at 12:45, Gabor Grothendieck wrote:
thanks for this, Gabor.

The class of the objects I am manipulating in my
package is c("count", "table").

It'd be nice to overload the "+" symbol so that I can add
two count objects like this with a simple "x+y".  To this end, I
defined a Ops.count() function that executed Gabor's summation.

But, this broke all sorts of functionality in the package,
because the ">" relation was not defined in my Ops.count()
function.

In my case, the only operation that I want to redefine is "+".
I want to leave all the others unchanged.

What is Best Practice for redefining just one binary operator?
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743
#
On 6/20/06, Robin Hankin <r.hankin at noc.soton.ac.uk> wrote:
This will define + but not the others:

"+.count" <- function(x,y) {
	both <- c(x,y)
	as.table(tapply(both, names(both), sum))
}