Menu
Coddy logo textTech

Logical Data Type

Part of the Fundamentals section of Coddy's R journey — lesson 7 of 78.

The logical data type can only hold two possible values: TRUE and FALSE. These values represent the concepts of true and false, which are fundamental for controlling program flow and making comparisons. Notice that both values are written in all capital letters without quotes.

Creating a logical variable follows the same pattern you've learned:

is_complete <- TRUE
has_error <- FALSE

Logical values become incredibly useful when your program needs to make decisions, check conditions, or store the results of comparisons. They form the foundation for controlling what your code does in different situations.

challenge icon

Challenge

Easy

Create three logical variables to represent different system states. First, create a variable called is_online and assign it the value TRUE. Then create a variable called has_permission and assign it the value FALSE. Finally, create a variable called system_ready and assign it the value TRUE. Display all three variables using the print() function.

Cheat sheet

The logical data type holds two possible values: TRUE and FALSE. Both values are written in all capital letters without quotes.

Creating logical variables:

is_complete <- TRUE
has_error <- FALSE

Logical values are used for making decisions, checking conditions, and storing comparison results.

Try it yourself

# TODO: Write your code here
# Create the three logical variables and display them using print()
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals