reorder.factor package:stats R Documentation _R_e_o_r_d_e_r _L_e_v_e_l_s _o_f _a _F_a_c_t_o_r _D_e_s_c_r_i_p_t_i_o_n: '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. _U_s_a_g_e: 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)) _A_r_g_u_m_e_n_t_s: x: a character vector or factor (possibly ordered) or whose levels will be reordered. X: a vector of the same length as 'x', whose subset of values for each unique level of 'x' determines the eventual order of that level. FUN: a 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'. ...: optional: extra arguments supplied to 'FUN' order: logical, whether return value will be an ordered factor rather than a factor. _V_a_l_u_e: 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. _A_u_t_h_o_r(_s): Deepayan Sarkar deepayan.sarkar@r-project.org _S_e_e _A_l_s_o: 'reorder.dendrogram', 'levels', 'relevel'. _E_x_a_m_p_l_e_s: 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")