What is tan() in R?

The tan() function in R returns the tangent of a number in radians.

The following illustration shows the mathematical representation of the tan() function.

Mathematical representation of tangent function

This tan() function only works for right-angled triangles.

Syntax

tan(num)

Parameter

This function requires a number that represents an angle in radians as a parameter.

To convert degrees to radians, use the following formula.

radians = degrees * ( pi / 180.0 )

Return value

tan() returns the tangent of a number (in radians) that is sent as a parameter.

Code

#Positive number in radians
a <- tan(2.3);
print(paste0("tan(2.3): ", a))
#negative number in radians
b <- tan(-2.3);
print(paste0("tan(-2.3): ", b))
#converting the degrees angle into radians and then applying tan()
#degrees = 45
c <- tan(45 * (pi / (180)));
print(paste0("tan(45 * (pi / (180))): ", c))

Free Resources