Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Logical Type | Data Types and Vectors
R Introduction

bookLogical Type

Note
Definition

Logical data type can store only two values: TRUE (or T) and FALSE (or F). These values are case-sensitive and are used to evaluate conditions and expressions.

Comparisons

Comparisons such as equality or greater-than tests produce logical results. These results are always either TRUE or FALSE.

Example

12
2 > 1 5 == 10
copy

Type Conversions

  • Number into logical: 0 becomes FALSE, while any non-zero number becomes TRUE;
  • String into logical:
    • 'F', 'false', 'False', 'FALSE' convert to FALSE;
    • 'T', 'true', 'True', 'TRUE' convert to TRUE;
    • Other values are converted into NA;
  • Logical into number: FALSE becomes 0 and TRUE becomes 1.
Task

Swipe to start coding

  1. Assign the result of the expression 19*54 > 76*13 to the variable logic.
  2. Show the value of the logic variable.
  3. Show the data type of the logic variable.
  4. Convert the logic variable to an integer and show the result.

Avoid using the print() function.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 4
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

Awesome!

Completion rate improved to 2.27

bookLogical Type

Swipe to show menu

Note
Definition

Logical data type can store only two values: TRUE (or T) and FALSE (or F). These values are case-sensitive and are used to evaluate conditions and expressions.

Comparisons

Comparisons such as equality or greater-than tests produce logical results. These results are always either TRUE or FALSE.

Example

12
2 > 1 5 == 10
copy

Type Conversions

  • Number into logical: 0 becomes FALSE, while any non-zero number becomes TRUE;
  • String into logical:
    • 'F', 'false', 'False', 'FALSE' convert to FALSE;
    • 'T', 'true', 'True', 'TRUE' convert to TRUE;
    • Other values are converted into NA;
  • Logical into number: FALSE becomes 0 and TRUE becomes 1.
Task

Swipe to start coding

  1. Assign the result of the expression 19*54 > 76*13 to the variable logic.
  2. Show the value of the logic variable.
  3. Show the data type of the logic variable.
  4. Convert the logic variable to an integer and show the result.

Avoid using the print() function.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 4
single

single

some-alt