R/peri.R

Defines functions peri

Documented in peri

#a function to calculate the perimeter of a 2D curve/function
peri <- function(df, xmin, xmax){
  ##error catching
  if(is.data.frame(df) == F){
    stop('The df argument has to be a data frame')
  }
  if( (is.numeric(xmin) == F) | (is.numeric(xmax) == F) ){
    stop('The xmax and xmin arguments have to be of type numeric')
  }
  if( (err.vec.dim.bit(xmin, 1) == T) | (err.vec.dim.bit(xmax, 1) == T) ){
    stop('xmax and xmin have to be vectors of length equal to 1')
  }


  ##core function
  df <- subset(df, X >= xmin)
  df <- subset(df, X <= xmax)
  L <- length(df$X)
  peri_vec <- NULL
  for (i in 1:(L-1) ) {
    peri_vec <- c( peri_vec, dis_eval(df[i,], df[i+1,]) )
  }
  return(sum(peri_vec))
}
Chitran1987/StatsChitran documentation built on Feb. 23, 2025, 8:30 p.m.