EVOLUTION-MANAGER
Edit File: round_to_fraction.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Round to the nearest fraction of a specified denominator.</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for round_to_fraction {janitor}"><tr><td>round_to_fraction {janitor}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Round to the nearest fraction of a specified denominator.</h2> <h3>Description</h3> <p>Round a decimal to the precise decimal value of a specified fractional denominator. Common use cases include addressing floating point imprecision and enforcing that data values fall into a certain set. </p> <p>E.g., if a decimal represents hours and values should be logged to the nearest minute, <code>round_to_fraction(x, 60)</code> would enforce that distribution and 0.57 would be rounded to 0.566667, the equivalent of 34/60. 0.56 would also be rounded to 34/60. </p> <p>Set <code>denominator = 1</code> to round to whole numbers. </p> <p>The <code>digits</code> argument allows for rounding of the subsequent result. </p> <h3>Usage</h3> <pre> round_to_fraction(x, denominator, digits = Inf) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>A numeric vector</p> </td></tr> <tr valign="top"><td><code>denominator</code></td> <td> <p>The denominator of the fraction for rounding (a scalar or vector positive integer).</p> </td></tr> <tr valign="top"><td><code>digits</code></td> <td> <p>Integer indicating the number of decimal places to be used after rounding to the fraction. This is passed to <code>base::round()</code>). Negative values are allowed (see Details). (<code>Inf</code> indicates no subsequent rounding)</p> </td></tr> </table> <h3>Details</h3> <p>If <code>digits</code> is <code>Inf</code>, <code>x</code> is rounded to the fraction and then kept at full precision. If <code>digits</code> is <code>"auto"</code>, the number of digits is automatically selected as <code>ceiling(log10(denominator)) + 1</code>. </p> <h3>Value</h3> <p>the input x rounded to a decimal value that has an integer numerator relative to <code>denominator</code> (possibly subsequently rounded to a number of decimal digits). </p> <h3>Examples</h3> <pre> round_to_fraction(1.6, denominator = 2) round_to_fraction(pi, denominator = 7) # 22/7 round_to_fraction(c(8.1, 9.2), denominator = c(7, 8)) round_to_fraction(c(8.1, 9.2), denominator = c(7, 8), digits = 3) round_to_fraction(c(8.1, 9.2, 10.3), denominator = c(7, 8, 1001), digits = "auto") </pre> <hr /><div style="text-align: center;">[Package <em>janitor</em> version 2.1.0 <a href="00Index.html">Index</a>]</div> </body></html>