CHAPTER 03
Beginner
R Syntax and Basics
Updated: May 18, 2026
5 min read
# CHAPTER 3
R Syntax and Basics
1. Chapter Introduction
Understanding R's syntax rules prevents the most common beginner errors. This chapter covers R's foundational syntax — how R reads code, comment conventions, output methods, and basic operations — culminating in a functional calculator application.2. R Syntax Fundamentals
r
3. Output Methods
r
4. Basic Arithmetic and Operations
r
5. Mini Project: Basic Calculator Application
r
6. Common Mistakes
-
=in comparison vs assignment: In R,=is assignment inside function calls;==is equality comparison. Use<-for assignment in scripts.
-
Forgetting
\nincat():print()adds a newline automatically.cat()does NOT — always add\nor usecat("text\n").
7. MCQs
Question 1
R is case-sensitive?
Question 2
cat() vs print() difference?
Question 3
Integer division in R uses?
Question 4
paste0("R", "Studio") returns?
Question 5
Modulo operator in R?
Question 6
sprintf("%.2f", 3.14159) returns?
Question 7
Valid R variable name?
Question 8
switch() in R is used for?
Question 9
log(100) in R computes?
Question 10
invisible(result) in a function?
8. Interview Questions
-
Q: What is the difference between
cat()andprint()in R?
-
Q: What does the
%%operator do in R?
9. Summary
R syntax: one statement per line,# for comments, <- for assignment. Output: print() (structured with [1] index), cat() (plain text), sprintf() (formatted). Arithmetic: +, -, *, /, ^, %%, %/%. R is case-sensitive. Variable names: snake_case recommended. switch() for multi-branch logic.