R sin() Function

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

Simple usage of sin() function in R

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.

Passing pi to the sin() function

vec1 <- pi / 2
vec2 <- -pi / 3

sin(vec1)
sin(vec2)

Output

[1] 1
[1] -0.8660254

Example 3: Using Vector

Using the sin() function to a 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

Leave a Comment