CHAPTER 05
Beginner
Operators and Expressions
Updated: May 18, 2026
5 min read
# CHAPTER 5
Operators and Expressions in R
1. Chapter Introduction
Operators are the building blocks of every R expression — from simple arithmetic to complex data filtering conditions. This chapter covers R's complete operator system with data analysis use cases.2. Arithmetic Operators
r
3. Comparison Operators
r
4. Logical Operators
r
5. Assignment and Special Operators
r
6. Operator Precedence
text
7. Common Mistakes
-
Using
&vs&&for if conditions:&is vectorized (returns vector);&&is scalar (returns one TRUE/FALSE). Always use&&and||inif()conditions.
-
==to compare with NA:x == NAis alwaysNA. Useis.na(x).
8. MCQs
Question 1
17 %% 5 in R returns?
Question 2
%in% operator checks?
Question 3
&& vs & difference?
Question 4
Floating point comparison should use?
Question 5
<<- operator does?
Question 6
!TRUE evaluates to?
Question 7
1:5 creates?
Question 8
xor(TRUE, FALSE) returns?
Question 9
dplyr::filter() uses :: to?
Question 10
|> in R 4.1+ is?
9. Interview Questions
-
Q: What is the difference between
&and&&in R?
-
Q: Why does
0.1 + 0.2 == 0.3return FALSE in R?
10. Summary
R operators: arithmetic (+, -, *, /, %/%, %%, ^), comparison (<, >, ==, !=, %in%), logical (&, |, !, &&, ||), assignment (<-, <<-), pipe (|>, %>%), sequence (:). Key rules: use &&/|| in if(), never == for NA/floats, %in% for membership, :: for explicit namespace. R's vectorized operators make filtering and transformation loop-free.