Greater and less than
Apart from equality operators, Filip also introduced the less than and greater than operators: < and >. You can also add an equal sign to express less than or equal to or greater than or equal to, respectively. Have a look at the following R expressions, that all evaluate to FALSE:
(1 + 2) > 4
"dog" < "Cats"
TRUE <= FALSE
Remember that for string comparison, R determines the greater than relationship based on alphabetical order. Also, keep in mind that TRUE is treated as 1 for arithmetic, and FALSE is treated as 0. Therefore, FALSE < TRUE is TRUE.
This exercise is part of the course
Intermediate R
Exercise instructions
Write R expressions to check whether:
-6 * 5 + 2is greater than or equal to-10 + 1.- "raining" is less than or equal to "raining dogs".
- TRUE is greater than FALSE.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Comparison of numerics
# Comparison of character strings
# Comparison of logicals