[R] Ordering data.frame based on class

From: Vincy Pyne <vincy_pyne_at_yahoo.ca>
Date: Mon, 28 Mar 2011 13:55:53 -0700 (PDT)


Dear R helpers

Suppose I have a data.frame as given below -

my_dat = data.frame(class = c("XYZ", "XYZ", "XYZ", "XYZ", "XYZ","ABC", "ABC", "ABC", "ABC", "ABC" ),  var1 = c(20, 14, 89, 81, 17, 44, 36, 41, 11, 36), var2 = c(1001, 250, 456, 740, 380, 641, 111, 209, 830, 920))

> my_dat

   class var1 var2
1    XYZ   20 1001
2    XYZ   14  250
3    XYZ   89  456
4    XYZ   81  740
5    XYZ   17  380
6    ABC   44  641
7    ABC   36  111
8    ABC   41  209
9    ABC   11 

 830
10   ABC  20  920 I wish to sort above data.frame class-wise on var1. Thus, Ineed to get
class                    var1        var2

 
 

  XYZ  
  14
  250    

  XYZ  
  17
  380    

  XYZ  
  20
  1001    

  XYZ  
  81
  740    

  XYZ  
  89
  456    

  ABC  
  11
  830    

  ABC  
  20
  920    

  ABC  
  36
  111
   

  ABC  
  41
  209    

  ABC  
  44
  641  

Kindly guide

Vincy

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 28 Mar 2011 - 20:59:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Mar 2011 - 21:10:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive