R/unwrap_angles.R

Defines functions unwrap_angles

Documented in unwrap_angles

# ---------------------------------------------------------------------------- #
#' unwrap_angles
#'
#' @description Add 360 degs an element in the input vector if elements are not sorted in ascending order.
#'
#' @param angles Vector containing angles
#'
#' @return angles in ascending order
#'
unwrap_angles <- function(angles){
  angles_unwraped = angles
  for(i in 2:length(angles)){
    if(angles_unwraped[i] < angles_unwraped[i-1]){
      angles_unwraped[i] <- angles_unwraped[i] + 360
    }
  }
  if(is.unsorted(angles_unwraped)){
    warning("unwrap_angles : angles are not sorted!")
  }
  return (angles_unwraped)
}
# ---------------------------------------------------------------------------- #

Try the VedicDateTime package in your browser

Any scripts or data that you put into this service are public.

VedicDateTime documentation built on Sept. 20, 2023, 9:08 a.m.