desc()

desc()

The desc() function can be used with the arrange() function to arrange a variable in a data frame in descending order.


Example 1: 

For instance, when we use the arrange() function to sort the Fingers data frame by Thumb, it will sort the values for Thumb in ascending order (smallest to largest) by default, like so:

# arrange Thumb in ascending order

arrange(Fingers, Thumb)


Example of output from running the code above:
output of arranging Thumb in ascending order

Example 2:

But if we want the values to be sorted in descending order (largest to smallest) we can include the desc() function in the argument for arrange(), like so:

# arrange Thumb in descending order

arrange(Fingers, desc(Thumb))


Example of output from running the code above:
Example output from arranging Thumb in descending order

    • Related Articles

    • arrange()

      The arrange() function will arrange a data frame by a specific variable, in ascending order. You can use the desc() argument with the arrange() function to arrange the data frame in descending order. NOTE: The arrange() function is similar to the ...
    • sort()

      The sort() function will sort a vector (or a single column in a data frame) by a specific variable, in ascending order. You can use the decreasing = TRUE argument with the sort() function to sort the data frame in descending order (be careful not to ...
    • asymptotic

      Asymptotic is used to describe a probability distribution with a tail (or tails) that goes on forever and ever.
    • Support Tickets

      Support Tickets This book includes an online Help Desk you can use to ask questions, report technical issues, and share your feedback.  How to Submit a Ticket You can submit a ticket from within the online textbook or by email.  Submit a Ticket from ...
    • Type I and Type II Error

      Type I and II Error describe the possible errors we might make when drawing conclusions about the DGP based on our data.  Type I error is when we should adopt the empty model but we adopt the complex model in error.  Type II error is when we should ...