R sqrt()
R sqrt() function is used to find the square root of a number.
In this tutorial, we will learn how to use sqrt()
function to compute the square root of given value.
Syntax
The syntax of sqrt()
function to compute square root of x
is
</>
Copy
sqrt(x)
Returns the square root of x
.
x
can be a numeric or complex vector or array.
Examples
In the following program, we will find the square root of a number 16
.
example.R
</>
Copy
x <- 16
result <- sqrt(x)
cat("The sqaure root of", x, "is :", result)
Output
The sqaure root of 16 is : 4
Now, let us take an array of numbers, and find their square roots.
example.R
</>
Copy
x <- array(c(1, 16, 9), dim=c(3,1))
result <- sqrt(x)
cat("The sqaure root of array [", x, "] is :", result)
Output
The sqaure root of array [ 1 16 9 ] is : 1 4 3
Conclusion
In this R Tutorial, we learned how to find the square root of a numeric value using sqrt()
function, with the help of examples.