Calculate Square root of a number in R Language – sqrt() Function
Square Root of a number is the value that yields the original number when multiplied by itself. If “x” is a number, its square root is written in mathematical notation as √x. we can calculate the square root in R using the sqrt() function.
In the R Programming Language, we have an inbuilt function known as the sqrt() Function to calculate the square root in R.
sqrt() function in R
To find a number’s square root in R, use the sqrt() function.
- The integer you wish to find the square root of is the only argument required.
- The function yields the supplied number’s positive square root.
x: Any numerical value greater than 0
Calculate Square root using sqrt() Function
x1 <- 16
x2 <- 18
Calculate Square root of a decimal number using sqrt() Function
x1 <- 8.34526
x2 <- -18
In sqrt(x2) : NaNs produced
Here, in the above code, NaN is produced because we passed a negative value in the sqrt() function.
Calculate Square Roots of Multiple Numbers in a Vector
(9, 25, 49, 64)
 3 5 7 8
we calculate the square roots of multiple numbers stored in a vector. The
sqrt() function is applied to each element in the vector, and the results are stored in another vector called
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!