R Tutorial R Charts & Graphs R Statistics R References

R - sin() Function



The R sin() function returns trigonometric sine of an angle (angle should be in radians). In special cases it returns the following:

  • If the argument is NaN or an infinity, then the result is NaN.

In the graph below, sin(x) vs x is plotted.

Sin Function

Syntax

sin(x)

Parameters

x Required. Specify column to compute on.

Return Value

Returns the trigonometric sine of specified angles.

Example:

In the example below, sin() function is used to find out the trigonometric sine of an angle.

#operating on single element atomic vector
print(sin(pi/6))
print(sin(pi/3))
print(sin(pi/2))

cat("\nOperating on vector\n")
#operating on vector
v <- c(pi/6, pi/4, pi/3)
print(sin(v))

cat("\nOperating on matrix\n")
#operating on matrix
m <- matrix(c(pi/6, pi/4, pi/3, pi/2, pi, NaN), nrow=2)
print(sin(m))

cat("\nOperating on first column of matrix\n")
#operating on first column of matrix
print(sin(m[,1]))

The output of the above code will be:

[1] 0.5
[1] 0.8660254
[1] 1

Operating on vector
[1] 0.5000000 0.7071068 0.8660254

Operating on matrix
          [,1]      [,2]         [,3]
[1,] 0.5000000 0.8660254 1.224647e-16
[2,] 0.7071068 1.0000000          NaN

Operating on first column of matrix
[1] 0.5000000 0.7071068

❮ R Math Functions

5