Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Logical Type | Section
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.
Compito

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.

Soluzione

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 14
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

close

bookLogical Type

Scorri per mostrare il 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.
Compito

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.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 14
single

single

some-alt