Concept Flow - Comparison operators
Start
Evaluate Left Value
Evaluate Right Value
Apply Comparison Operator
Result: TRUE or FALSE
End
The program compares two values using a comparison operator and produces TRUE or FALSE as the result.
a <- 5 b <- 3 result <- a > b print(result)
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Assign a | a <- 5 | a = 5 |
| 2 | Assign b | b <- 3 | b = 3 |
| 3 | Compare a > b | 5 > 3 | TRUE |
| 4 | Assign result | result <- TRUE | result = TRUE |
| 5 | Print result | print(result) | [1] TRUE |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|---|---|
| a | undefined | 5 | 5 | 5 | 5 | 5 |
| b | undefined | undefined | 3 | 3 | 3 | 3 |
| result | undefined | undefined | undefined | undefined | TRUE | TRUE |
Comparison operators in R compare two values and return TRUE or FALSE. Common operators: >, <, >=, <=, ==, != Syntax example: result <- a > b Result is logical (TRUE/FALSE). Used for decision making and filtering.
==.= is for assignment, != means not equal, and <> is not valid in R.!= to check if two values are not equal.<> and !== are not valid in R, and =! is incorrect syntax.x <- 5
y <- 7
x > y
if (x = 10) { print("Yes") }==, not =.= assigns a value, but == tests equality. Using = in if condition causes an error or unexpected behavior.v <- c(3, 5, 7, 9) to keep only values greater than or equal to 5. Which R expression correctly uses comparison operators to do this?=>, =, and >== are invalid operators in R.Pass the test and this pattern moves unknown