Day 12: The worst thing people do in UNO

If you're familiar with the card game UNO

(or any card game really)

You know there are two types of friends when it comes to shuffling the cards

  1. Shuffles like a pro

  2. Shuffles like they're a seal
    (randomly slapping cards against each other)

Now... I'm a decent player when it comes to UNO but... my SO *ahem*

Let's just say she's unfortunate when it comes to this game 😆

The last time we played, there were six of us.

The first game went on fairly fast but the second game sprung a surprise...

We got almost the same cards

How?

Because the cards were shuffled by a friend... who... can't shuffle 😭

Now data can't be taken for granted like a card deck

Data requires to be sorted in the right manner, or, in other words, arranged.

Continuing the flights data set from yesterday

(remember to run library(nycflights13) and install the package if you're new)

How do you arrange your data in a specific manner?

Using... *drumroll*

The arrange function :P

flights |>
arrange(year, month, day, dep_time)

Want to arrange something in descending order?

Simply use the 'desc' function

flights |>
arrange(desc(day))

Now...

unfortunately, you can't use multiple variables within the desc function

However...

if you want to use multiple variables you can use the 'across' function

flights |>
arrange(across(c(year, month, day, dep_time),desc))

c stands for concatenate which is used to group multiple variables together (instead of using them seperately)

These are a few ways to arrange data in ascending and descending order.

Of course, it'll get more powerful when you start combining filter and arrange together but we move on to the rest of the dplyr before we begin these combinations

Happy coding :)


Previous
Previous

Day 13: Let's remove some duplicates

Next
Next

Day 11: I got excited and made a boo-boo