Trusted answers to developer questions

harris910

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 radians a <- cos(2.3); print(paste0("cos(2.3): ", a)) #negative number in radians b <- cos(-2.3); print(paste0("cos(-2.3): ", b)) #converting the degrees angle into radians and then applying cos() #degrees = 180 c <- cos(180 * (pi / (180))); print(paste0("cos(180 * (pi / (180))): ", c))

RELATED TAGS

r

math

cosine

communitycreator

CONTRIBUTOR

harris910

RELATED COURSES

View all Courses

Keep Exploring

Related Courses