R/root_it.R

Defines functions root_it

Documented in root_it

#' Calculate the nth root of a numeric value
#' 
#' @param x Numeric value
#' @param power The n value, e.g. 2 for square root
#' @param replace_NA A character vector specifying what to replace NA values with. Defaults to 0.
#' 
#' @examples 
#' root_it(100, 2)
#' root_it(1024, 10)
#' root_it(81, 4)
#' @export
root_it <- function(x, power, replace_NA = 0){
  result <- exp(log(x) / power)
  ifelse(is.na(result), replace_NA, result)
}
martinctc/modeltoolbox documentation built on May 12, 2020, 3:12 a.m.