Logical data type support in R is actually such a powerful feature for data analysis.

Even when you don’t have Logical column you can create one easily.

Here’s US Flight data.

There is a column called ARR_DELAY (Arrival Delay Time) at the right hand side in the above picture.

And let’s say I want to create a column to indicate whether each flight was really a delayed arrival (the arrival delay time is greater than 0) or was actually an early arrival (the arrival delay time is less than 0).

You can create such column with Mutate step with logical calculation.

Select Create Calculation from the column header menu.

Type the following logical (or conditional) calculation in the Calculation input form.

ARR_DELAY > 0

This will evaluate each row and return TRUE when a given value matches this condition.

Then, just looking at the result column under Summary view, we can see 30.13% of the flights are actually delayed (TRUE).

Logical Operator to Create Logical Column

The logical calculation doesn’t need to be always ‘greater than’ operator. There are other operators like below.

Multiple Choice Condition

For example, let’s say we want to know what is the percentage of the flights that are AA, UA, and DL?

Then, we can create a new calculation by selecting ‘Create Calculation’ from the column header menu.

Then, type the following condition.

CARRIER %in% c("AA", "DL", "UA")

Once it’s run, we can see that 42.89% of the flights are either AA, DL, or UA.

Once we get this new Logical column created, then we can show the percentage of AA, DL, UA flights for each state, for example.

Loading...