简体   繁体   中英

R sort data frame

I need to sort a data.fram by the first column (Trade Value). The properties of my data.frame are:

 str(Data_OUT)
'data.frame':   68 obs. of  9 variables:
 $ Trade Value              : num  6 7.5 8 8.5 9 9 9.5 10 10.5 10.5 ...
 $ Running Back.Player Name : chr  "" "" "" "" ...
 $ Running Back.Trend       : num  NA NA NA NA NA NA 0 0 NA NA ...
 $ Wide Receiver.Player Name: chr  "Mohamed Sanu" "Marquise Brown" "Tyrell Williams" "Marvin Jones" ...
 $ Wide Receiver.Trend      : num  0 0 0 0 0 0 0 0 0 0 ...
 $ Tight End.Player Name    : chr  "" "" "" "" ...
 $ Tight End.Trend          : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Quarterback.Player Name  : chr  "" "" "" "" ...
 $ Quarterback.Trend        : num  NA NA NA NA NA NA 0 NA NA NA ...

summary(Data_OUT)
     Trade Value    Running Back.Player Name Running Back.Trend Wide Receiver.Player Name
     Min.   : 6.00   Length:68                Min.   :0          Length:68                
     1st Qu.:12.88   Class :character         1st Qu.:0          Class :character         
     Median :21.25   Mode  :character         Median :0          Mode  :character         
     Mean   :24.73                            Mean   :0                                   
     3rd Qu.:32.00                            3rd Qu.:0                                   
     Max.   :69.00                            Max.   :0                                   
                                              NA's   :33                                  
     Wide Receiver.Trend Tight End.Player Name Tight End.Trend Quarterback.Player Name
     Min.   :0           Length:68             Min.   :0       Length:68              
     1st Qu.:0           Class :character      1st Qu.:0       Class :character       
     Median :0           Mode  :character      Median :0       Mode  :character       
     Mean   :0                                 Mean   :0                              
     3rd Qu.:0                                 3rd Qu.:0                              
     Max.   :0                                 Max.   :0                              
     NA's   :32                                NA's   :60                             
     Quarterback.Trend
     Min.   :0        
     1st Qu.:0        
     Median :0        
     Mean   :0        
     3rd Qu.:0        
     Max.   :0        
     NA's   :59      

I am trying to use this code:

Data_OUT <- Data_OUT %>% dplyr::arrange(desc('Trade Value'))

but the result is that the table is sort ascending instead of descending.

and I have tried:

Data_OUT <- Data_OUT[order(-'Trend Value'),]

but I get the error: "Error in -"Trend Value": invalid argument to unary operator"

Anyone have other suggestions?

Thanks!

You can change to, be careful with the ` and '

Data_OUT <- Data_OUT %>% dplyr::arrange(desc(`Trade Value`))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM