重新排列数据集

时间:2016-03-15 15:02:35

标签: r dataset

我有一个名为count的数据集。它包含了2015年被美国警察杀害的所有人的信息。目前,该数据集是根据这些人被杀害的一年中的一天订购的。

我想要做的是根据他们被杀的状态重新排列数据集我怎样才能在R中做到这一点?

以下是我的数据集的摘要说明:

   uid                         name           age                 gender    
 Min.   :   2.0   Robert Edwards    :   3   24     : 46   Female        :  53  
 1st Qu.: 289.8   John Allen        :   2   25     : 41   Male          :1086  
 Median : 580.5   Jose Rodriguez    :   2   35     : 40   Non-conforming:   1  
 Mean   : 582.2   Miguel Martinez   :   2   28     : 38                        
 3rd Qu.: 875.2   Unknown           :   2   31     : 38                        
 Max.   :1164.0   A'donte Washington:   1   34     : 38                        
                  (Other)           :1128   (Other):899                        
                raceethnicity       month          day             year     
 White                 :578   July     :123   Min.   : 1.00   Min.   :2015  
 Black                 :303   March    :114   1st Qu.: 8.00   1st Qu.:2015  
 Hispanic/Latino       :194   April    :102   Median :15.00   Median :2015  
 Asian/Pacific Islander: 24   August   :102   Mean   :15.64   Mean   :2015  
 Unknown               : 23   September: 95   3rd Qu.:23.00   3rd Qu.:2015  
 Native American       : 13   December : 94   Max.   :31.00   Max.   :2015  
 (Other)               :  5   (Other)  :510                                 
                    streetaddress            city          state               classification
                           :   6   Los Angeles :  20   CA     :210   Death in custody :  41  
 Unknown                   :   3   Houston     :  17   TX     :108   Gunshot          :1015  
 13630 Veterans Memorial Dr:   2   Las Vegas   :  12   FL     : 71   Other            :   1  
 1800 E San Bernardino Ave :   2   Chicago     :  10   AZ     : 44   Struck by vehicle:  33  
 2040 California Ave       :   2   Indianapolis:  10   GA     : 39   Taser            :  50  
 4700 W Erie St            :   2   Phoenix     :  10   OK     : 38                           
 (Other)                   :1123   (Other)     :1061   (Other):630                           
                                  lawenforcementagency     armed    
 Los Angeles Police Department              :  23      Firearm:554  
 Los Angeles County Sheriff's Department    :  15      No     :224  
 Houston Police Department                  :  11      Knife  :155  
 Chicago Police Department                  :  10      Other  : 61  
 New York Police Department                 :  10      Unknown: 59  
 Indianapolis Metropolitan Police Department:   9      Vehicle: 43  
 (Other)                                    :1062      (Other): 44

1 个答案:

答案 0 :(得分:0)

可能你可以使用像订单功能一样简单的东西。

dataframe<-dataframe[,order(state),decreasing=TRUE)]

你可以试试这个。