Transform a vector into a format that will be sorted in descending order. This is useful within arrange().

desc(x)

Arguments

x

vector to transform

Examples

desc(1:10)
#> [1] -1 -2 -3 -4 -5 -6 -7 -8 -9 -10
desc(factor(letters))
#> [1] -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 #> [20] -20 -21 -22 -23 -24 -25 -26
first_day <- seq(as.Date("1910/1/1"), as.Date("1920/1/1"), "years") desc(first_day)
#> [1] 21915 21550 21185 20819 20454 20089 19724 19358 18993 18628 18263
starwars %>% arrange(desc(mass))
#> # A tibble: 87 x 14 #> name height mass hair_color skin_color eye_color birth_year sex gender #> <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> #> 1 Jabba … 175 1358 NA green-tan… orange 600 herm… mascu… #> 2 Grievo… 216 159 none brown, wh… green, y… NA male mascu… #> 3 IG-88 200 140 none metal red 15 none mascu… #> 4 Darth … 202 136 none white yellow 41.9 male mascu… #> 5 Tarfful 234 136 brown brown blue NA male mascu… #> 6 Owen L… 178 120 brown, grey light blue 52 male mascu… #> 7 Bossk 190 113 none green red 53 male mascu… #> 8 Chewba… 228 112 brown unknown blue 200 male mascu… #> 9 Jek To… 180 110 brown fair blue NA male mascu… #> 10 Dexter… 198 102 none brown yellow NA male mascu… #> # … with 77 more rows, and 5 more variables: homeworld <chr>, species <chr>, #> # films <list>, vehicles <list>, starships <list>