Logical Type
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
122 > 1 5 == 10
Type Conversions
- Number into logical:
0
becomesFALSE
, while any non-zero number becomesTRUE
; - String into logical:
'F'
,'false'
,'False'
,'FALSE'
convert toFALSE
;'T'
,'true'
,'True'
,'TRUE'
convert toTRUE
;- Other values are converted into
NA
;
- Logical into number:
FALSE
becomes0
andTRUE
becomes1
.
Swipe to start coding
- Assign the result of the expression
19*54 > 76*13
to the variablelogic
. - Show the value of the
logic
variable. - Show the data type of the
logic
variable. - Convert the
logic
variable to an integer and show the result.
Avoid using the print()
function.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 2.27
Logical Type
Swipe to show menu
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
122 > 1 5 == 10
Type Conversions
- Number into logical:
0
becomesFALSE
, while any non-zero number becomesTRUE
; - String into logical:
'F'
,'false'
,'False'
,'FALSE'
convert toFALSE
;'T'
,'true'
,'True'
,'TRUE'
convert toTRUE
;- Other values are converted into
NA
;
- Logical into number:
FALSE
becomes0
andTRUE
becomes1
.
Swipe to start coding
- Assign the result of the expression
19*54 > 76*13
to the variablelogic
. - Show the value of the
logic
variable. - Show the data type of the
logic
variable. - Convert the
logic
variable to an integer and show the result.
Avoid using the print()
function.
Solution
Thanks for your feedback!
single