美文网首页R/Python
R语言排序函数

R语言排序函数

作者: 茶苯海 | 来源:发表于2017-02-10 17:38 被阅读42次

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))

相关文章

网友评论

    本文标题:R语言排序函数

    本文链接:https://www.haomeiwen.com/subject/przgittx.html