R/ratios.R

Defines functions ratios

Documented in ratios

#' @title Computes ratios of numerical values
#'
#' @description Computes ratios of numerical values
#'
#' @param x values to compute the ratio from
#'
#' @return a dataframe of $ratio, $x1 and $x2
#'
#' @examples
#' ratios(c(20,40,100,400))
#'
#' @export

ratios <- function(x)
{

  t <- sort(x)

  lx <- length(x)

  tri.mat <- matrix(rep(seq_len(lx - 1) + 1, lx-1), nrow = lx - 1)

  r <- tri.mat[lower.tri(tri.mat, diag = T)]
  l <- rep(seq_len(lx - 1), times = rev(seq_len(lx - 1)))

  ratio <- t[r]/t[l]

  xl <- t[l]
  xr <- t[r]

  res <- list(ratio = ratio, x1 = xl, x2 = xr)

  res <- as.data.frame(res)

  return(res)

}

Try the DecomposeR package in your browser

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

DecomposeR documentation built on Feb. 16, 2023, 9:50 p.m.