[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  groupGeneric: S3 Group Generic Functions

##  Description

Group generic methods can be defined for four pre-specified groups of
functions, ` Math ` , ` Ops ` , ` Summary ` and ` Complex ` . (There are no
objects of these names in base  R  , but there are in the  methods  package.)

A method defined for an individual member of the group takes precedence over a
method defined for the group as a whole.

##  Usage

    
    
    ## S3 methods for group generics have prototypes:
    Math(x, \dots)
    Ops(e1, e2)
    Complex(z)
    Summary(\dots, na.rm = FALSE)

##  Arguments

x, z, e1, e2

objects.

…

further arguments passed to methods.

na.rm

logical: should missing values be removed?

##  Technical Details

These functions are all primitive and [ internal generic
](/link/internal%20generic?package=base&version=3.6.2) .

The details of method dispatch and variables such as ` .Generic ` are
discussed in the help for ` [ UseMethod
](/link/UseMethod?package=base&version=3.6.2) ` . There are a few small
differences:

  * For the operators of group ` Ops ` , the object ` .Method ` is a length-two character vector with elements the methods selected for the left and right arguments respectively. (If no method was selected, the corresponding element is ` "" ` .) 

  * Object ` .Group ` records the group used for dispatch (if a specific method is used this is ` "" ` ). 

##  Details

There are four _groups_ for which S3 methods can be written, namely the `
"Math" ` , ` "Ops" ` , ` "Summary" ` and ` "Complex" ` groups. These are not
R  objects in base  R  , but methods can be supplied for them and base  R
contains ` [ factor ](/link/factor?package=base&version=3.6.2) ` , ` [
data.frame ](/link/data.frame?package=base&version=3.6.2) ` and ` [ difftime
](/link/difftime?package=base&version=3.6.2) ` methods for the first three
groups. (There is also a ` [ ordered
](/link/ordered?package=base&version=3.6.2) ` method for ` Ops ` , ` [ POSIXt
](/link/POSIXt?package=base&version=3.6.2) ` and ` [ Date
](/link/Date?package=base&version=3.6.2) ` methods for ` Math ` and ` Ops ` ,
` [ package_version ](/link/package_version?package=base&version=3.6.2) `
methods for ` Ops ` and ` Summary ` , as well as a ` [ ts
](/link/ts?package=base&version=3.6.2) ` method for ` Ops ` in package  stats
.)

  1. Group ` "Math" ` : 

     * ` abs ` , ` sign ` , ` sqrt ` , ` floor ` , ` ceiling ` , ` trunc ` , ` round ` , ` signif `

     * ` exp ` , ` log ` , ` expm1 ` , ` log1p ` , ` cos ` , ` sin ` , ` tan ` , ` cospi ` , ` sinpi ` , ` tanpi ` , ` acos ` , ` asin ` , ` atan `

` cosh ` , ` sinh ` , ` tanh ` , ` acosh ` , ` asinh ` , ` atanh `

     * ` lgamma ` , ` gamma ` , ` digamma ` , ` trigamma `

     * ` cumsum ` , ` cumprod ` , ` cummax ` , ` cummin `

Members of this group dispatch on ` x ` . Most members accept only one
argument, but members ` log ` , ` round ` and ` signif ` accept one or two
arguments, and ` trunc ` accepts one or more.

  2. Group ` "Ops" ` : 

     * ` "+" ` , ` "-" ` , ` "*" ` , ` "/" ` , ` "^" ` , ` "%%" ` , ` "%/%" `

     * ` "&" ` , ` "|" ` , ` "!" `

     * ` "==" ` , ` "!=" ` , ` "<" ` , ` "<=" ` , ` ">=" ` , ` ">" `

This group contains both binary and unary operators ( ` + ` , ` - ` and ` ! `
): when a unary operator is encountered the ` Ops ` method is called with one
argument and ` e2 ` is missing.

The classes of both arguments are considered in dispatching any member of this
group. For each argument its vector of classes is examined to see if there is
a matching specific (preferred) or ` Ops ` method. If a method is found for
just one argument or the same method is found for both, it is used. If
different methods are found, there is a warning about ‘incompatible methods’:
in that case or if no me