# What is cos() in R?

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.

Mathematical representation of the cosine function

Note: This cos() function only works for right-angled triangles.

## Syntax

cos(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

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

### Code

#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))

Learn in-demand tech skills in half the time