Appendix E — Extras: Arranging rows

You may want to sort your rows by a specific column so that values are arranged in ascending or descending order. This can be done using the function called arrange(). Again, arrange() takes the dataset as the first argument, followed by the columns that you wish to arrange data by. By default, arrange() orders in ascending order.

docs/learning.qmd
post_meal_data |>
  arrange(Age)

arrange() also arranges parameters of type character alphabetically:

docs/learning.qmd
post_meal_data |>
  arrange(Group)

If we want to order the column based on descending order, this can be done with desc().

docs/learning.qmd
post_meal_data |>
  arrange(desc(Age))

You can also order your data by multiple columns. For instance, we could arrange first by Group and then by age.

docs/learning.qmd
post_meal_data |>
  arrange(Group, Age)