Learn R Programming

vfunc (version 1.0)

Math: Math group generic functions in the vfunc package: trig, exponential, log, etc.

Description

The S4 Math group contains 35 functions including sin(), log(), etc. The vfunc equivalents are capitalized, as in Sin(), Log(), etc.

Usage

Abs(x)
Sign(x)
Sqrt(x)
Ceiling(x)
Floor(x)
Trunc(x)
Cummax(x)
Cummin(x)
Cumprod(x)
Cumsum(x)
Log(x)
Log10(x)
Log2(x)
Log1p(x)
Acos(x)
Acosh(x)
Asin(x)
Asinh(x)
Atan(x)
Atanh(x)
Exp(x)
Expm1(x)
Cos(x)
Cosh(x)
Cospi(x)
Sin(x)
Sinh(x)
Sinpi(x)
Tan(x)
Tanh(x)
Tanpi(x)
Gamma(x)
Lgamma(x)
Digamma(x)
Trigamma(x)

Value

Given a numeric, return a numeric; given a vf, return a vf

Arguments

x

Generally take a single argument of class numeric, function, or vf

Author

Robin K. S. Hankin

Details

The reason for this rather untransparent device is that primitive functions such as sin() behave somewhat differently from other functions. We have:


Sin <- as.vf(function(x){sin(x)})
setMethod("sin", "vf", function(x){as.vf(function(o){Sin(x(o))})})

We define Sin() to be an object of class vf; the call to setMethod() ensures that Sin(f) operates as intended.

Examples

Run this code

Sin + Exp

c((Sin + Exp)(.02232) ,sin(0.02232) +  exp(0.02232))

Run the code above in your browser using DataLab