reorder.factor {Hmisc} | R Documentation |
Reorders the levels of a factor variable by the values or the summarized values of another variable
reorder.factor(x, v, FUN = mean, ...)
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 |
a new factor vector
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)