Convert decimals to a character vector of fractions

fracture(
  x,
  ...,
  denom = NULL,
  base_10 = FALSE,
  common_denom = FALSE,
  mixed = FALSE,
  max_denom = 1e+07
)

as.fracture(x)

is.fracture(x)

Arguments

x

A vector of decimals or, for as.fracture(), a matrix created by frac_mat()

...

These dots are for future extensions and must be empty.

denom

If denom is not NULL, all fractions will have a denominator of denom. This will ignore all other arguments that affect the denominator.

base_10

If TRUE, all denominators will be a power of 10.

common_denom

If TRUE, all fractions will have the same denominator.

If the least common denominator is greater than max_denom, max_denom is used.

mixed

If TRUE, integer components will be displayed separately from fractional components for x values greater than 1.

If FALSE, improper fractions will be used for x values greater than 1.

max_denom

All denominators will be less than or equal to max_denom.

If base_10 is TRUE, the maximum denominator will be the largest power of 10 less than max_denom.

A max_denom greater than the inverse square root of machine double epsilon will produce a warning because floating point rounding errors can occur when denominators grow too large.

Value

A character vector.

See also

frac_mat() to return a matrix of numerators and denominators.

Examples

x <- (6:1) / (1:6)

fracture(x)
#> [1] 6/1 5/2 4/3 3/4 2/5 1/6
fracture(x, common_denom = TRUE)
#> [1] 360/60 150/60 80/60  45/60  24/60  10/60 

fracture(x, base_10 = TRUE)
#> [1] 6/1               25/10             13333333/10000000 75/100           
#> [5] 4/10              1666667/10000000 
fracture(x, base_10 = TRUE, max_denom = 100)
#> [1] 6/1     25/10   133/100 75/100  4/10    17/100 
fracture(x, base_10 = TRUE, common_denom = TRUE)
#> [1] 60000000/10000000 25000000/10000000 13333333/10000000 7500000/10000000 
#> [5] 4000000/10000000  1666667/10000000 
fracture(x, base_10 = TRUE, common_denom = TRUE, max_denom = 100)
#> [1] 600/100 250/100 133/100 75/100  40/100  17/100 

fracture(x, mixed = TRUE)
#> [1] "6"     "2 1/2" "1 1/3" "3/4"   "2/5"   "1/6"  
fracture(x, mixed = TRUE, common_denom = TRUE)
#> [1] "6 0/60"  "2 30/60" "1 20/60" "45/60"   "24/60"   "10/60"  
fracture(x, mixed = TRUE, base_10 = TRUE)
#> [1] "6"                  "2 5/10"             "1 3333333/10000000"
#> [4] "75/100"             "4/10"               "1666667/10000000"  
fracture(x, mixed = TRUE, base_10 = TRUE, max_denom = 100)
#> [1] "6"        "2 5/10"   "1 33/100" "75/100"   "4/10"     "17/100"  
fracture(x, mixed = TRUE, base_10 = TRUE, common_denom = TRUE)
#> [1] "6 0/10000000"       "2 5000000/10000000" "1 3333333/10000000"
#> [4] "7500000/10000000"   "4000000/10000000"   "1666667/10000000"  
fracture(x, mixed = TRUE, base_10 = TRUE, common_denom = TRUE, max_denom = 100)
#> [1] "6 0/100"  "2 50/100" "1 33/100" "75/100"   "40/100"   "17/100"