All trigonometric functions that are available in R are the sine, cosine, and tangent method and their inverse methods.
cos in R
The cos() is a built-in mathematical R function that computes the cosine value of numeric value data. The cos() function takes a numerical value as an argument and returns the cosine value.
To calculate the cosine of a value in R, use the cos() function.
The cos() function takes x as an argument is either numeric or complex vectors.
This code doesn’t give you the correct result, however, because R always works with angles in radians, not in degrees. So pay attention to the fact; if you forget, the resulting bugs may bite you hard in the er, leg.
The correct way to calculate the cosine of an angle of 30 degrees then uses the following code.
cos(30 * pi / 180)
Cos value of pi in R
The pi in R is an inbuilt constant. So let’s find the cos() value of the pi constant.
Let’s pass the -pi.
Applying cos() function to a Vector
To create a Vector in R, use the c() function. Then, add three elements of a vector using the pi constant.
rv <- c(pi, pi / 4, pi / 3) cos(rv)
 -1.0000000 0.7071068 0.5000000
That is it for the cos() function in R.
Krunal Lathiya is an Information Technology Engineer by education and web developer by profession. He has worked with many back-end platforms, including Node.js, PHP, and Python. In addition, Krunal has excellent knowledge of Data Science and Machine Learning, and he is an expert in R Language. Krunal has written many programming blogs, which showcases his vast expertise in this field.