You need polyroot() :
polyroot(z = c(-16,0,0,0,1))
Where z is the "vector of polynomial coefficients in ascending order."
Vector I, passed in z in the above example, is a compact representation of this equation:
-16x^0 + 0x^1 + 0x^2 + 0x^3 + 1x^4 = 0 x^4 - 16 = 0 x^4 = 16 x = 16^(1/4)
Edit:
If the polyroot syntax polyroot you, you can write a wrapper function that offers you a more convenient (if not universal) interface:
nRoot <- function(x, root) { polyroot(c(-x, rep(0, root-1), 1)) } nRoot(16, 4)
source share