Special Functions in R

Special Functions

Special functions are really standard functions in practice, but they serve to expand the range of infix operators, extraction, and replacement functions in R.

Infix Operators

R can be used to define new infix operators which can be named “%anything%”.  These operators extend base functionality as needed.  To print the new operators, use the get() function.

The code below defines an new operator that raises a matrix to a power:

Extraction and Replacement Functions

R has many extraction and replacement functions.  Newly created functions are needed when data objects are customized with new attributes or meta data.

As a simple example, suppose we want to create a replacement function that assigns a new attribute named memo to the data object.  memo is intended to hold a brief description of a data object and its variables. Next, the corresponding extraction function is defined to retrieve the memo attribute assigned to the data.  Both functions start naturally enough with the attr() function:

Back | Next

Leave a Reply

Your email address will not be published. Required fields are marked *

15 − eight =