desc: Descending order

Description Usage Arguments Examples

View source: R/desc.r

Description

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

Usage

1
desc(x)

Arguments

x

vector to transform

Examples

1
2
3
4
5
6
7
desc(1:10)
desc(factor(letters))

first_day <- seq(as.Date("1910/1/1"), as.Date("1920/1/1"), "years")
desc(first_day)

starwars %>% arrange(desc(mass))

Example output

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

 [1]  -1  -2  -3  -4  -5  -6  -7  -8  -9 -10
 [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
 [1] 21915 21550 21185 20819 20454 20089 19724 19358 18993 18628 18263
# A tibble: 87 x 13
                    name height  mass  hair_color       skin_color
                   <chr>  <int> <dbl>       <chr>            <chr>
 1 Jabba Desilijic Tiure    175  1358        <NA> green-tan, brown
 2              Grievous    216   159        none     brown, white
 3                 IG-88    200   140        none            metal
 4           Darth Vader    202   136        none            white
 5               Tarfful    234   136       brown            brown
 6             Owen Lars    178   120 brown, grey            light
 7                 Bossk    190   113        none            green
 8             Chewbacca    228   112       brown          unknown
 9      Jek Tono Porkins    180   110       brown             fair
10       Dexter Jettster    198   102        none            brown
# ... with 77 more rows, and 8 more variables: eye_color <chr>,
#   birth_year <dbl>, gender <chr>, homeworld <chr>, species <chr>,
#   films <list>, vehicles <list>, starships <list>

dplyr documentation built on June 19, 2021, 1:07 a.m.