Extracting Values from Date / Time Data

Sometimes you want to compare data by Month names like January, February, or Day of Week like Sunday, Monday, etc.

There is a comprehensive set of functions from ‘lubridate’ package and you can use them easily in Exploratory. Let’s take a look.

Extracting Month Name

Let’s start from extracting the month names.

Select ‘Extract’ -> ‘Month Name’ from the column header menu.

This will populate month function like the below.

month(start_time, label = TRUE, abbr = TRUE)

month function extracts the month information from Date & Time data. You can use ‘label’ argument to decide whether you want it to return something like “Jan”, “Feb”, “March”, etc. or 1, 2, 3. etc.

The cool thing about this is that it returns the values as ‘Ordered Factor’, which means it has the order (sorting) information embedded in the data.

And, in Exploratory the order information is respected in Charts.

Month Name in Bar Chart

Extracting Day of Week

Next, let’s extract the day of week.

Select ‘Extract’ -> ‘Day of Week’ from the column header menu.

This will populate wday function like the following.

wday(start_time, label = TRUE, abbr = TRUE)

You can use ‘label’ argument to decide whether you want it to return something like ‘Sun’, ‘Mon’, ‘Tue’, etc. or 1, 2, 3, etc.

This wday function also returns the values as ‘Ordered Factor’. This means, when you summarize or sort the data, it will appropriately return the data in an order that you would expect, like below.