how to use the nthroot function in R

Viewed 5767

I am trying to use the nthroot function from the pracma package. However, whenever I run it I get an error:

Error in nthroot(x, 5) : could not find function "nthroot"

I tried installing the pracma package but that didn't help either. Could anyone give me any ideas on why this isn't working?

2 Answers

nthroot handles negatives, e.g. returning nthroot(-2,3) == -1.259921, rather than NA

To define this yourself:

nthroot = function(x,n) {
  (abs(x)^(1/n))*sign(x)
}

Just do

x ^ (1 / n)

Where n is the root.

Related