EVOLUTION-MANAGER
Edit File: reorder.factor.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: Reorder Levels of a Factor</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 reorder.default {stats}"><tr><td>reorder.default {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Reorder Levels of a Factor</h2> <h3>Description</h3> <p><code>reorder</code> is a generic function. The <code>"default"</code> method treats its first argument as a categorical variable, and reorders its levels based on the values of a second variable, usually numeric. </p> <h3>Usage</h3> <pre> reorder(x, ...) ## Default S3 method: reorder(x, X, FUN = mean, ..., order = is.ordered(x)) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>an atomic vector, usually a <code><a href="../../base/html/factor.html">factor</a></code> (possibly ordered). The vector is treated as a categorical variable whose levels will be reordered. If <code>x</code> is not a factor, its unique values will be used as the implicit levels. </p> </td></tr> <tr valign="top"><td><code>X</code></td> <td> <p> a vector of the same length as <code>x</code>, whose subset of values for each unique level of <code>x</code> determines the eventual order of that level. </p> </td></tr> <tr valign="top"><td><code>FUN</code></td> <td> <p>a <code><a href="../../base/html/function.html">function</a></code> whose first argument is a vector and returns a scalar, to be applied to each subset of <code>X</code> determined by the levels of <code>x</code>.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p> optional: extra arguments supplied to <code>FUN</code></p> </td></tr> <tr valign="top"><td><code>order</code></td> <td> <p> logical, whether return value will be an ordered factor rather than a factor. </p> </td></tr> </table> <h3>Details</h3> <p>This, as <code><a href="relevel.html">relevel</a>()</code>, is a special case of simply calling <code><a href="../../base/html/factor.html">factor</a>(x, levels = levels(x)[....])</code>. </p> <h3>Value</h3> <p>A factor or an ordered factor (depending on the value of <code>order</code>), with the order of the levels determined by <code>FUN</code> applied to <code>X</code> grouped by <code>x</code>. The levels are ordered such that the values returned by <code>FUN</code> are in increasing order. Empty levels will be dropped. </p> <p>Additionally, the values of <code>FUN</code> applied to the subsets of <code>X</code> (in the original order of the levels of <code>x</code>) is returned as the <code>"scores"</code> attribute. </p> <h3>Author(s)</h3> <p>Deepayan Sarkar <a href="mailto:deepayan.sarkar@r-project.org">deepayan.sarkar@r-project.org</a></p> <h3>See Also</h3> <p><code><a href="reorder.dendrogram.html">reorder.dendrogram</a></code>, <code><a href="../../base/html/levels.html">levels</a></code>, <code><a href="relevel.html">relevel</a></code>. </p> <h3>Examples</h3> <pre> require(graphics) bymedian <- with(InsectSprays, reorder(spray, count, median)) boxplot(count ~ bymedian, data = InsectSprays, xlab = "Type of spray", ylab = "Insect count", main = "InsectSprays data", varwidth = TRUE, col = "lightgray") </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>