reorder.factor {stats} | R Documentation |
reorder
is a generic function. Its "factor"
method
reorders the levels of a factor depending on values of a second
variable, usually numeric. The "character"
method is a
convenient alias.
reorder(x, ...)
## S3 method for class 'factor'
reorder(x, X, FUN = mean, ...,
order = is.ordered(x))
## S3 method for class 'character'
reorder(x, X, FUN = mean, ...,
order = is.ordered(x))
x |
a character vector or factor (possibly ordered) or whose levels will be reordered. |
X |
a vector of the same length as |
FUN |
a function whose first argument is a vector and
returns a scalar, to be applied to each subset of |
... |
optional: extra arguments supplied to |
order |
logical, whether return value will be an ordered factor rather than a factor. |
A factor or an ordered factor (depending on the value of
order
), with the order of the levels determined by
FUN
applied to X
grouped by x
. The
levels are ordered such that the values returned by FUN
are in increasing order.
Additionally, the values of FUN
applied to the subsets of
X
(in the original order of the levels of x
) is returned
as the "scores"
attribute.
Deepayan Sarkar deepayan.sarkar@r-project.org
reorder.dendrogram
, levels
,
relevel
.
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")