How to Create Logical Data (TRUE/FALSE) with Logical Calculation

Logical data type column has the values that are either TRUE or FALSE. It can be called ‘Binary’ sometimes.

It is convenient for data analysis, and you need it when you want to run some type of machine learning algorithms such as binary classification.

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

Here’s US Flight data.

And let’s say we want to create a column to indicate whether each flight was really delayed (the arrival delay time is greater than 0) or not (the arrival delay time is less than 0) based on the ARR_DELAY column.

We can create a calculation with such logical condition.

Select ‘Create Calculation (Mutate)’ 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.

Going to Summary view, we can see 30.13% of the flights are actually delayed (TRUE).

Other Logical Operators

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.