What is sin() in R?

The sin() function in R returns the sine of a number in radians.

The illustration below shows the mathematical representation of the sin() function.

Mathematical representation of the sine function

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

Syntax

sin(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 )

Return value

sin() returns the sine of a number (in radians) that is sent as a parameter. The return value is in the range [-1,1].

Code

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