EVOLUTION-MANAGER
Edit File: frank.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: Fast rank</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 frank {data.table}"><tr><td>frank {data.table}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Fast rank</h2> <h3>Description</h3> <p>Similar to <code>base::rank</code> but <em>much faster</em>. And it accepts vectors, lists, <code>data.frame</code>s or <code>data.table</code>s as input. In addition to the <code>ties.method</code> possibilities provided by <code>base::rank</code>, it also provides <code>ties.method="dense"</code>. </p> <p>Like <code><a href="setorder.html">forder</a></code>, sorting is done in "C-locale"; in particular, this may affect how capital/lowercase letters are ranked. See Details on <code>forder</code> for more. </p> <p><code>bit64::integer64</code> type is also supported. </p> <h3>Usage</h3> <pre> frank(x, ..., na.last=TRUE, ties.method=c("average", "first", "last", "random", "max", "min", "dense")) frankv(x, cols=seq_along(x), order=1L, na.last=TRUE, ties.method=c("average", "first", "last", "random", "max", "min", "dense")) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p> A vector, or list with all its elements identical in length or <code>data.frame</code> or <code>data.table</code>. </p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p> Only for <code>list</code>s, <code>data.frame</code>s and <code>data.table</code>s. The columns to calculate ranks based on. Do not quote column names. If <code>...</code> is missing, all columns are considered by default. To sort by a column in descending order prefix <code>"-"</code>, e.g., <code>frank(x, a, -b, c)</code>. <code>-b</code> works when <code>b</code> is of type <code>character</code> as well.</p> </td></tr> <tr valign="top"><td><code>cols</code></td> <td> <p> A <code>character</code> vector of column names (or numbers) of <code>x</code>, for which to obtain ranks. </p> </td></tr> <tr valign="top"><td><code>order</code></td> <td> <p> An <code>integer</code> vector with only possible values of 1 and -1, corresponding to ascending and descending order. The length of <code>order</code> must be either 1 or equal to that of <code>cols</code>. If <code>length(order) == 1</code>, it is recycled to <code>length(cols)</code>. </p> </td></tr> <tr valign="top"><td><code>na.last</code></td> <td> <p> Control treatment of <code>NA</code>s. If <code>TRUE</code>, missing values in the data are put last; if <code>FALSE</code>, they are put first; if <code>NA</code>, they are removed; if <code>"keep"</code> they are kept with rank <code>NA</code>. </p> </td></tr> <tr valign="top"><td><code>ties.method</code></td> <td> <p> A character string specifying how ties are treated, see <code>Details</code>. </p> </td></tr> </table> <h3>Details</h3> <p>To be consistent with other <code>data.table</code> operations, <code>NA</code>s are considered identical to other <code>NA</code>s (and <code>NaN</code>s to other <code>NaN</code>s), unlike <code>base::rank</code>. Therefore, for <code>na.last=TRUE</code> and <code>na.last=FALSE</code>, <code>NA</code>s (and <code>NaN</code>s) are given identical ranks, unlike <code><a href="../../base/html/rank.html">rank</a></code>. </p> <p><code>frank</code> is not limited to vectors. It accepts <code>data.table</code>s (and <code>list</code>s and <code>data.frame</code>s) as well. It accepts unquoted column names (with names preceded with a <code>-</code> sign for descending order, even on character vectors), for e.g., <code>frank(DT, a, -b, c, ties.method="first")</code> where <code>a,b,c</code> are columns in <code>DT</code>. The equivalent in <code>frankv</code> is the <code>order</code> argument. </p> <p>In addition to the <code>ties.method</code> values possible using base's <code><a href="../../base/html/rank.html">rank</a></code>, it also provides another additional argument <code>"dense"</code> which returns the ranks without any gaps in the ranking. See examples. </p> <h3>Value</h3> <p>A numeric vector of length equal to <code>NROW(x)</code> (unless <code>na.last = NA</code>, when missing values are removed). The vector is of integer type unless <code>ties.method = "average"</code> when it is of double type (irrespective of ties). </p> <h3>See Also</h3> <p><code><a href="data.table.html">data.table</a></code>, <code><a href="setkey.html">setkey</a></code>, <code><a href="setorder.html">setorder</a></code> </p> <h3>Examples</h3> <pre> # on vectors x = c(4, 1, 4, NA, 1, NA, 4) # NAs are considered identical (unlike base R) # default is average frankv(x) # na.last=TRUE frankv(x, na.last=FALSE) # ties.method = min frankv(x, ties.method="min") # ties.method = dense frankv(x, ties.method="dense") # on data.table DT = data.table(x, y=c(1, 1, 1, 0, NA, 0, 2)) frankv(DT, cols="x") # same as frankv(x) from before frankv(DT, cols="x", na.last="keep") frankv(DT, cols="x", ties.method="dense", na.last=NA) frank(DT, x, ties.method="dense", na.last=NA) # equivalent of above using frank # on both columns frankv(DT, ties.method="first", na.last="keep") frank(DT, ties.method="first", na.last="keep") # equivalent of above using frank # order argument frank(DT, x, -y, ties.method="first") # equivalent of above using frankv frankv(DT, order=c(1L, -1L), ties.method="first") </pre> <hr /><div style="text-align: center;">[Package <em>data.table</em> version 1.14.4 <a href="00Index.html">Index</a>]</div> </body></html>