Friday, August 11, 2017

abs() and sqrt() {base}


abs() function computes the absolute value of x, while sqrt() function computes the square root of x.

The parameters of the functions are:
 x: numeric vector or array
abs(10)
## [1] 10
abs(-10)
## [1] 10
sqrt(10)
## [1] 3.162278
sqrt(-10)
## Warning in sqrt(-10): NaNs produced
## [1] NaN
sqrt(abs(-10))
## [1] 3.162278
plot(15:-15, sqrt(abs(15:-15)),  col = "orange")
lines(spline(15:-15, sqrt(abs(15:-15))), col = "gold")

No comments:

Post a Comment

duplicated() {base}

duplicated()  function determines which elements are duplicated and returns a logical vector. The parameters of the function are:   ...