ecd.rational: Utility to convert a numeric to a rational

View source: R/ecd-rational-method.R

ecd.rationalR Documentation

Utility to convert a numeric to a rational

Description

Convert a numeric x to rational p/q, which is then used for polynomial construction. It can be used for displaying the time as fraction of a year too.

Usage

ecd.rational(
  x,
  pref.denominator = numeric(0),
  cycles = 10,
  max.denominator = 500,
  as.character = FALSE
)

Arguments

x

numeric

pref.denominator

numeric, a list of preferred integer denominators to conform to, default is numeric(0).

cycles

numeric, maximum number of steps, default is 10.

max.denominator

numeric, maximum denominator when the loop of trial should stop, default is 500.

as.character

logical, if specified, convert to character of p/q, default is FALSE.

Value

vector of two integers, representing numerator and denominator. If as.character is true, then return character instead of the rational pair. If x is a vector and as.character is false, return a matrix of length(x) by 2.

Examples

pq1 <- ecd.rational(2.5)
pq2 <- ecd.rational(1/250)

ecd documentation built on May 10, 2022, 1:07 a.m.