Last chance! 50% off unlimited learning
Sale ends in
reorder
is a generic function. The "default"
method
treats its first argument as a categorical variable, and reorders its
levels based on the values of a second variable, usually numeric.reorder(x, …)# S3 method for default
reorder(x, X, FUN = mean, …,
order = is.ordered(x))
factor
(possibly
ordered). The vector is treated as a categorical variable whose
levels will be reordered. If x
is not a factor, its unique
values will be used as the implicit levels.
x
, whose subset
of values for each unique level of x
determines the
eventual order of that level.
function
whose first argument is a vector
and returns a scalar, to be applied to each subset of X
determined by the levels of x
.FUN
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. Empty levels will be dropped. 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.relevel()
, is a special case of simply calling
factor(x, levels = levels(x)[....])
.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")
Run the code above in your browser using DataLab