order()返回的值表示位置,依次对应的是向量的最小值、次小值、第三小值......最大值
rank() sort() order() 和 reorder()
data<=c(2,3,6,1)
reorder()函数在ggplot2中见过:
x = reorder(Var1, -Freq) Var1是分类变量,Freq是数值型变量
help(recorder) 的结果:
Reorder Levels of a Factor
Description
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.
Usage
reorder(x, ...)
Default S3 method:
reorder(x, X, FUN = mean, ...,
order = is.ordered(x))
>x<-c(97,93,85,74,32,100,99,67)>sort(x)
[1] 32 67 74 85 93 97 99 100
>order(x)
[1] 5 8 4 3 2 1 7 6
>rank(x)
[1] 6 5 4 3 1 8 7 2
有的是直接对值排序,有的是直接对索引进行排序