atan() Function in R with Example

To calculate the inverse tangent value of the input numeric value in R, use the atan() function.

atan() in R

The atan() is an inbuilt R trigonometric function that returns the radian arctangent of number data. The atan() method is used to calculate the inverse tangent value of the numeric value passed to it as an argument.

Syntax

atan(x)

Parameters

The atan() function takes as an input value.

Example

Calculate the inverse tangent of a value.

v1 <- -1
v2 <- 0.5
v3 <- 0

atan(v1)
atan(v2)
atan(v3)

Output

[1] -0.7853982
[1] 0.4636476
[1] 0

If you pass the 0 to the atan() function, it will return 0.

Plot the atan() function to a graph

We can use the seq() function to create a series of values and pass that to the plot() function, which will create a line chart.

dt <- seq(-1, 1, by = 0.01)
plot(dt, atan(x), typ = "l", col = "red")
abline(v = 0, lty = 6, col = "blue")

Output

R atan() Function

Applying atan() function to a Vector

To define a Vector in R, use the c() function. Then pass that vector to the atan() function.

rv <- c(-1, 0.5, 0, 0.5, 1)
atan(rv)

Output

[1] -0.7853982 0.4636476 0.0000000 0.4636476 0.7853982

Passing a pi to the atan() function

The pi is an inbuilt constant in R programming, and its value is 3.141593.

Let’s find the pi constant’s atan() value.

atan(pi)

Output

[1] 1.262627

Let’s see another example of pi.

atan(pi / 4)

Output

[1] 0.6657738

That is it for atan() function in R programming.

See also

R acos()

R tan()

R sin()

R asin()

Leave a Comment