In a right-angled triangle, the tangent of an angle is:
The length of the side opposite the angle divided by the length of the adjacent side.
The abbreviation is tan is the following.
tan(θ) = opposite / adjacent
tan() Function in R
The tan() is an inbuilt mathematical R function that calculates the tangent value of numeric value. The tanpi() method calculates the tangent of the input value, the multiples of π.
To calculate the tangent in R programming, use the tan() function.
Syntax
tan(x)
Parameters
The tan() function takes a numeric value.
Example
x1 <- -45
x2 <- -60
tan(x1)
tan(x2)
Output
[1] -1.619775
[1] -0.3200404
Applying pi to the tan() function
The pi is an inbuilt constant whose value is 3.141593. Let’s pass the pi to the tan() function and see the output.
x1 <- pi
x2 <- pi / 3
tan(x1)
tan(x2)
Output
[1] -1.224647e-16
[1] 1.732051
Applying a tan() function to Vector
To create a Vector in R, use the c() function. Let’s create a vector and pass that vector to the tanpi() function.
dt <- c(1, 0.5, -1, -0.25, 0.5, 2 / 3)
tanpi(dt)
Output
[1] 0.000000 NaN 0.000000 -1.000000 NaN -1.732051
Warning message:
In tanpi(dt) : NaNs produced
That is it for tan() function in R.