Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Logical Type | Section
Practice
Projects
Quizzes & Challenges
Frågesporter
Challenges
/
Essential R Programming for Absolute Beginners - 1768563985826

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.
Uppgift

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.

Lösning

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 14
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

close

bookLogical Type

Svep för att visa menyn

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.
Uppgift

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.

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 14
single

single

some-alt