R Tutorial R Charts & Graphs R Statistics R Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

R - tan() Function



The R tan() function returns trigonometric tangent of an angle (angle should be in radians). In special cases it returns the following:

  • If the argument is NaN or an infinity, then the result is NaN.

Syntax

tan(x)

Parameters

x Specify column to compute on.

Return Value

Returns the trigonometric tangent of specified angles.

Example:

In the example below, tan() function is used to find out the trigonometric tangent of an angle.

#operating on single element atomic vector
print(tan(pi/6))
print(tan(pi/3))
print(tan(pi/2))

cat("\nOperating on vector\n")
#operating on vector
v <- c(pi/6, pi/4, pi/3)
print(tan(v))

cat("\nOperating on matrix\n")
#operating on matrix
m <- matrix(c(pi/6, pi/4, pi/3, pi/2, pi, NaN), nrow=2)
print(tan(m))

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

The output of the above code will be:

[1] 0.5773503
[1] 1.732051
[1] 1.633124e+16

Operating on vector
[1] 0.5773503 1.0000000 1.7320508

Operating on matrix
          [,1]         [,2]          [,3]
[1,] 0.5773503 1.732051e+00 -1.224647e-16
[2,] 1.0000000 1.633124e+16           NaN

Operating on first column of matrix
[1] 0.5773503 1.0000000

❮ R Math Functions

5