Share
The cos()
function in R calculates the cosine of a number in radians.
The following illustration shows the mathematical representation of the cos()
function.
Note: This
cos()
function only works for right-angled triangles.
cos(num)
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 )
cos()
returns the cosine of a number that is sent as a parameter. The return value is in the range [-1,1].
#positive number in radiansa <- cos(2.3);print(paste0("cos(2.3): ", a))#negative number in radiansb <- cos(-2.3);print(paste0("cos(-2.3): ", b))#converting the degrees angle into radians and then applying cos()#degrees = 180c <- cos(180 * (pi / (180)));print(paste0("cos(180 * (pi / (180))): ", c))