Last data update: 2014.03.03

R: Miscellaneous Mathematical Functions
MathFunR Documentation

Miscellaneous Mathematical Functions

Description

abs(x) computes the absolute value of x, sqrt(x) computes the (principal) square root of x, √{x}.

The naming follows the standard for computer languages such as C or Fortran.

Usage

abs(x)
sqrt(x)

Arguments

x

a numeric or complex vector or array.

Details

These are internal generic primitive functions: methods can be defined for them individually or via the Math group generic. For complex arguments (and the default method), z, abs(z) == Mod(z) and sqrt(z) == z^0.5.

abs(x) returns an integer vector when x is integer or logical.

S4 methods

Both are S4 generic and members of the Math group generic.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

Arithmetic for simple, log for logarithmic, sin for trigonometric, and Special for special mathematical functions.

‘plotmath’ for the use of sqrt in plot annotation.

Examples

require(stats) # for spline
require(graphics)
xx <- -9:9
plot(xx, sqrt(abs(xx)),  col = "red")
lines(spline(xx, sqrt(abs(xx)), n=101), col = "pink")

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(base)
> png(filename="/home/ddbj/snapshot/RGM3/R_rel/result/base/MathFun.Rd_%03d_medium.png", width=480, height=480)
> ### Name: MathFun
> ### Title: Miscellaneous Mathematical Functions
> ### Aliases: abs sqrt
> ### Keywords: math
> 
> ### ** Examples
> 
> require(stats) # for spline
> require(graphics)
> xx <- -9:9
> plot(xx, sqrt(abs(xx)),  col = "red")
> lines(spline(xx, sqrt(abs(xx)), n=101), col = "pink")
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>