0Pricing
R Academy · Lesson

Basic Arithmetic and Variables

Practice simple arithmetic operations in R and understand how to store values in variables.

Basic Arithmetic and Variables is a free R Academy lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the R Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

1

Introduction to Arithmetic in R

R can be used as a simple calculator to perform arithmetic operations.

Basic Arithmetic and Variables — illustration 1

2

Basic Arithmetic Operations

R supports common mathematical operations:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Exponentiation (^)
  • Modulo (%%)

3

Performing Calculations

Try performing basic calculations in R:

5 + 3
10 - 2
4 * 6
8 / 2
2^3
10 %% 3

4

Variables in R

Variables store values that can be reused.

x <- 10
y <- 5
z <- x + y

5

Assigning Values to Variables

Use the assignment operator <- to store values in variables.

6

Variable Naming Rules

Variable names:

  • Can contain letters, numbers, and underscores.
  • Cannot start with a number.
  • Are case-sensitive (e.g., Var and var are different).

7

Using Variables in Expressions

You can use variables in calculations:

x <- 10
y <- 2
z <- x * y

8

9

Checking Variable Types

You can check the type of a variable using the class() function.

x <- 42
class(x)

10

Summary

In this lesson, you learned how to:

  • Perform basic arithmetic operations.
  • Use variables to store values.
  • Check variable types.
Basic Arithmetic and Variables — illustration 10

Frequently asked questions

Is the “Basic Arithmetic and Variables” lesson free?

Yes — the full text of “Basic Arithmetic and Variables” is free to read here on the web, and the R Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the R Academy course, upgrade to CoddyKit PRO.

What will I learn in “Basic Arithmetic and Variables”?

Practice simple arithmetic operations in R and understand how to store values in variables. You practise R Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start R Academy?

No prior experience is required. R Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Basic Arithmetic and Variables” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this R Academy lesson?

Yes. Every R Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Getting Started with RStudio
  2. Basic Arithmetic and Variables
  3. Workspaces and Projects
← Back to R Academy