3.5 Commands and Calculations

3.5.1 Typing Commands at the R Console

R is an interactive language — you type commands directly into the console, press Enter, and R immediately returns the output.

print("Hello, World!")
## [1] "Hello, World!"

3.5.2 Doing Simple Calculations with R

R works as both a programming language and a calculator. You can perform arithmetic operations including addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^).

3 * 5
## [1] 15

3.5.3 Storing a Number As a Variable

You can store values as variables using the assignment operator <-, then use those variables in later calculations. This is essential for building up complex analyses step by step.

x <- 10
x * 2
## [1] 20