reorder.factor {Hmisc}R Documentation

Reorder Factor Levels

Description

Reorders the levels of a factor variable by the values or the summarized values of another variable

Usage

reorder.factor(x, v, FUN = mean, ...)

Arguments

x a factor variable
v a numeric variable the same length as x
FUN a statistical summarization function applied to v by levels of x
... other arguments passed to FUN

Value

a new factor vector

See Also

factor

Examples

x <- factor(c('a','b','b','c'))
v <- c(3,-1,1,-5)
w <- reorder.factor(x, v)  # uses FUN=mean
w
levels(w)
class(w)

[Package Hmisc version 3.0-10 Index]