R Tutorial R Charts & Graphs R Statistics R References

R - atan() Function



The R atan() function returns arc tangent of a value. The return value will be in the range -𝜋/2 through 𝜋/2. In special cases it returns the following:

  • If the argument is NaN, then the result is NaN.

Note: atan() is the inverse of tan().

Syntax

atan(x)

Parameters

x Required. Specify column to compute on.

Return Value

Returns the arc tangent of the value.

Example:

In the example below, atan() function is used to find out the arc tangent of the value.

#operating on single element atomic vector
print(atan(-2))
print(atan(0))
print(atan(2))

cat("\nOperating on vector\n")
#operating on vector
v <- c(0, 1, 2)
print(atan(v))

cat("\nOperating on matrix\n")
#operating on matrix
m <- matrix(c(-2, -1, 0, 1, 2, NaN), nrow=2)
print(atan(m))

cat("\nOperating on first column of matrix\n")
#operating on first column of matrix
print(atan(m[,1]))

The output of the above code will be:

[1] -1.107149
[1] 0
[1] 1.107149

Operating on vector
[1] 0.0000000 0.7853982 1.1071487

Operating on matrix
           [,1]      [,2]     [,3]
[1,] -1.1071487 0.0000000 1.107149
[2,] -0.7853982 0.7853982      NaN

Operating on first column of matrix
[1] -1.1071487 -0.7853982

❮ R Math Functions

5