R - Coerce methods (Object Class conversion)

Card Puncher Data Processing


Type Coercion in R.

The function as turns object into an object of class Class. In doing so, it applies a “coerce method”.

The implicitly defined coerce methods may be overridden by a call to setAs.


Coerce methods have two arguments in method signatures:

  • from: the class of the object
  • to: the desired coerce class.

These functions must not be called directly, but are used to store tables of methods for the use of as, directly and for replacements.


Function: coerce (package methods)
from="ANY", to="array"
from="ANY", to="call"
from="ANY", to="character"
from="ANY", to="complex"
from="ANY", to="environment"
from="ANY", to="expression"
from="ANY", to="function"
from="ANY", to="integer"
from="ANY", to="list"
from="ANY", to="logical"
from="ANY", to="matrix"
from="ANY", to="name"
from="ANY", to="NULL"
from="ANY", to="numeric"
from="ANY", to="S3"
from="ANY", to="S4"
from="ANY", to="ts"
from="ANY", to="vector"
from="character", to="signature"
from="character", to="SuperClassMethod"
from="color", to="HLS"
from="color", to="HSV"
from="color", to="LAB"
from="color", to="LUV"
from="color", to="polarLAB"
from="color", to="polarLUV"
from="color", to="RGB"
from="color", to="sRGB"
from="color", to="XYZ"
from="derivedDefaultMethod", to="function"
from="function", to="classGeneratorFunction"
from="function", to="OptionalFunction"
from="groupGenericFunction", to="genericFunction"
from="NULL", to="OptionalFunction"
from="NULL", to="optionalMethod"
from="oldClass", to="S3"

Documentation / Reference


Discover More
Card Puncher Data Processing
R - Class

A class is just an attribute of an object. You can remove the attribute with the function . The class with then become the type A list can have different class. unclass returns (a copy of) its...
Card Puncher Data Processing
R - Join Data Frame (Merge)

where: the “by” parameters specifies the join column. Default: join by common variable names The by.x and by.y parameters must be used if the matching variables have different names the “all”...
Card Puncher Data Processing
R - Vector

The Vector in R contains elements of the same class. A Vector with different class of objects is a list. A vector (as every object) can also have . Almost all data in R is a vector or is based upon...
Card Puncher Data Processing
R - rep (repetition of element)

where: x is an object to replicate (a vector (of any mode including a list) or a factor or (for rep only) a POSIXct or POSIXlt or Date object; or an S4 object containing such an object. times is an...

Share this page:
Follow us:
Task Runner