sqrt()

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

The sqrt() function computes the square root of numeric values in R. It operates element-wise on vectors.

Syntax

sqrt(x)

Parameters

ParameterTypeDefaultDescription
xnumericA numeric vector or scalar

Examples

Basic usage

# Square root of a single value
sqrt(16)
# [1] 4

sqrt(0)
# [1] 0

sqrt(2)
# [1] 1.414214

Working with vectors

# Square root of a vector
sqrt(c(4, 9, 16, 25))
# [1] 2 3 4 5

sqrt(1:10)
# [1] 1.000000 1.414214 1.732051 2.000000 2.236068 2.449490 2.645751 2.828427 3.000000 3.162278

Handling negative values

# Square root of negative values returns NaN
sqrt(-1)
# [1] NaN

# Use complex() for complex square roots
sqrt(-1 + 0i)
# [1] 0+1i

Common Patterns

Standard deviation calculation

# Population standard deviation
x <- c(10, 12, 14, 16, 18)
sqrt(mean((x - mean(x))^2))
# [1] 2.828427

Distance calculations

# Euclidean distance in 2D
x1 <- 0; y1 <- 0
x2 <- 3; y2 <- 4
sqrt((x2 - x1)^2 + (y2 - y1)^2)
# [1] 5

See Also