sort()是對向量進行從小到大的排序
rank()返回的是對向量中每個數值對應的秩
order()返回的值表示位置,依次對應的是向量的最小值、次小值、第三小值......最大值
rank() sort() order()
和 reorder()
data<=c(2,3,6,1)
sort(data)
[1] 1 2 3 6
rank(data)
[1] 2 3 4 1
order(data)
[1] 4 1 2 3
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))