zoukankan      html  css  js  c++  java
  • 4-6 R语言函数 排序

    #sort:对向量进行排序;返回排好序的内容
    #order:返回排好序的内容的下标/多个排序标准
    
    > x <- data.frame(v1=1:5,v2=c(10,7,9,6,8),v3=11:15,v4=c(1,1,2,2,1))
    
    > sort(x$v2)
    [1]  6  7  8  9 10
    
    > sort(x$v2,decreasing = TRUE)
    [1] 10  9  8  7  6
    
    > order(x$v2)
    [1] 4 2 5 3 1
    
    > x[order(x$v2),]
      v1 v2 v3 v4
    4  4  6 14  2
    2  2  7 12  1
    5  5  8 15  1
    3  3  9 13  2
    1  1 10 11  1
    
    > x[order(x$v4,x$v2,decreasing = TRUE),]
      v1 v2 v3 v4
    3  3  9 13  2
    4  4  6 14  2
    1  1 10 11  1
    5  5  8 15  1
    2  2  7 12  1
    
    
  • 相关阅读:
    你不是真正的快乐
    春天里
    一生有你
    故乡
    第一天
    直来直往
    恋恋风尘
    烦恼歌
    because of you
    从头再来
  • 原文地址:https://www.cnblogs.com/hankleo/p/9942345.html
Copyright © 2011-2022 走看看