The sqrt()
function in R is used to calculate the square root of a non-negative number.
Figure 1 shows the mathematical representation of the sqrt()
function.
sqrt(number)
sqrt()
requires a non-negative number as a parameter.
sqrt()
returns the square root of the number sent as a parameter.
If a negative number is sent as a parameter, then
sqrt()
returnsNaN
, along with awarning
message.
#Perfect square roota <- sqrt(4);print(paste0("sqrt(4): ", a))b <- sqrt(0);print(paste0("sqrt(0): ", b))#simple numberc <- sqrt(5);print(paste0("sqrt(5): ", c))d <- sqrt(4.5);print(paste0("sqrt(4.5): ", d))#negative numbere <- sqrt(-2);print(paste0("sqrt(-2): ", e))