sin()

sin(x)
Returns: numeric · Updated March 13, 2026 · Base Functions
trigonometry math sin base

The sin() function computes the trigonometric sine of numeric values in R. It operates element-wise on vectors and accepts angles in radians.

Syntax

sin(x)

Parameters

ParameterTypeDefaultDescription
xnumericNumeric vector or single value representing an angle in radians

Examples

Basic usage

# Compute sine for a single angle (pi/4 = 45 degrees)
sin(pi / 4)
# [1] 0.7071068

sin(0)
# [1] 0

sin(pi / 2)
# [1] 1

Working with vectors

# Compute sine for multiple angles
angles <- c(0, pi/6, pi/4, pi/3, pi/2)
sin(angles)
# [1] 0.0000000 0.5000000 0.7071068 0.8660254 1.0000000

Converting degrees to radians

# Convert degrees to radians before using trig functions
deg_to_rad <- function(deg) deg * pi / 180

sin(deg_to_rad(30))
# [1] 0.5

sin(deg_to_rad(90))
# [1] 1

Common Patterns

Creating periodic data

# Generate one period of sine wave
x <- seq(0, 2 * pi, length.out = 100)
y <- sin(x)
plot(x, y, type = "l")

Circular coordinates

# Calculate coordinates on a unit circle
theta <- seq(0, 2 * pi, length.out = 9)[-1]
x <- cos(theta)
y <- sin(theta)
data.frame(angle = round(theta, 2), x = round(x, 2), y = round(y, 2))

See Also