The sin() function in R is used to calculate the sine of a given value or vector of values. For example, sin(0) returns 0 and sin(pi/2) returns 1.
Syntax
sin(number)
Parameters
number: It accepts a number representing an angle in radians as a parameter.
Return value
It returns the sine of a number (in radians) sent as a parameter.
Example 1: Basic usage
vec1 <- -120
vec2 <- 90
vec3 <- 3.8
vec4 <- -1.9
sin(vec1)
sin(vec2)
sin(vec3)
sin(vec4)
Output
[1] -0.5806112
[1] 0.8939967
[1] -0.6118579
[1] -0.9463001
Example 2: Passing pi
Let’s pass the pi and see the output.
vec1 <- pi / 2
vec2 <- -pi / 3
sin(vec1)
sin(vec2)
Output
[1] 1
[1] -0.8660254
Example 3: Using Vector
vec <- c(pi / 2, - pi / 2, pi, pi / 3)
sin(vec)
Output
[1] 1.000000e+00 -1.000000e+00 1.224647e-16 8.660254e-01
Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.