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 <- FALSELogical 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
EasyCreate 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 <- FALSELogical 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()This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators (AND, OR)Logical Operators Part 2 (NOT)Recap - Simple LogicVectorized Logic Part 1Vectorized Logic Part 22Variables and Data Types
Numeric Data TypeInteger Data TypeCharacter Data TypeLogical Data TypeChecking Data TypesNaming ConventionsMissing Values: NARecap - Variable Creation8Loops
For LoopWhile LoopBreakNext (Continue)Recap - FactorialSequence Generation (seq, :)Nested LoopsRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsInteger Division and ModuloAssignment OperatorsRecap - Simple MathComparison Operators6Basic IO
Print OutputCat for OutputOutput With VariablesReading Input with readline()Type Conversion BasicsRecap - Age CalculatorRecap - True or False9Functions
Declaring a FunctionFunction ArgumentsReturn ValuesRecap - Sigma FunctionRecap - Validation FunctionDefault Parameter Values