Related Articles

Related Articles

Calculate Square root of a number in R Language – sqrt() Function
  • Last Updated : 01 Jun, 2020

sqrt() function in R Language is used to calculate the mathematical square-root of the value passed to it as argument.

Syntax: sqrt(x)

Parameter:
x: Any numerical value greater than 0

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R code to calculate square root of a number
  
x1 <- 16
x2 <- 18
  
# Using sqrt() Function
sqrt(x1)
sqrt(x2)

chevron_right


Output:



[1] 4
[1] 4.242641

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R code to calculate square root of a number
  
x1 <- 8.34526
x2 <- -18
  
# Using sqrt() Function
sqrt(x1)
sqrt(x2)

chevron_right


Output:

[1] 2.888816
[1] NaN
Warning message:
In sqrt(x2) : NaNs produced

Here, in the above code, NaN is produced because we passed a negative value in the sqrt() function.

My Personal Notes arrow_drop_up
Recommended Articles
Page :