cos() function is a built-in function in R that calculates the cosine of a single number or a vector of numbers. This guide shows how to use the cos() function in R.
Syntax
cos(x)
Argument
- x = It is the numeric vector you want to calculate the cosine of.
Here are some examples of the cos() function in R:
Example 1: Calculate the cosine of a number
#calculating the cosine value of a number
cos(0)
#calculating the cosine value of a number stored in a variable
x = 5
cos(x)
Output
[1] 1
[1] 0.2836622
Example 2: Calculate the cosine of a vector
#calculating the cosine value of a vector
x = (c(0,1, 2))
cos(x)
Output
[1] 1.0000000 0.5403023 -0.4161468