0Pricing
R Academy · Lesson

Working with Vectors and Matrices

Create and manipulate vectors and matrices to perform basic mathematical and data operations.

Working with Vectors and Matrices 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 Vectors in R

Vectors are the most basic data structure in R. They store elements of the same type.

Working with Vectors and Matrices — illustration 1

2

Creating Vectors

You can create vectors using the c() function.

numbers <- c(1, 2, 3, 4, 5)
numbers

3

Vector Operations

Vectors support element-wise operations.

x <- c(2, 4, 6)
y <- c(1, 1, 1)
z <- x + y

4

Accessing Vector Elements

You can access elements using indices.

numbers <- c(10, 20, 30, 40, 50)
numbers[2]

5

Introduction to Matrices

Matrices store data in rows and columns, containing only one type of data.

6

Creating Matrices

You can create matrices using the matrix() function.

mat <- matrix(1:9, nrow=3, ncol=3)
mat

7

Accessing Matrix Elements

You can access elements using row and column indices.

mat[2,3]

8

9

Performing Matrix Operations

You can perform arithmetic operations on matrices.

mat1 <- matrix(1:4, nrow=2)
mat2 <- matrix(5:8, nrow=2)
result <- mat1 + mat2

10

Summary

In this lesson, you learned:

  • How to create and manipulate vectors.
  • How to create and access matrices.
  • Basic vector and matrix operations.
Working with Vectors and Matrices — illustration 10

Frequently asked questions

Is the “Working with Vectors and Matrices” lesson free?

Yes — the full text of “Working with Vectors and Matrices” 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 “Working with Vectors and Matrices”?

Create and manipulate vectors and matrices to perform basic mathematical and data operations. 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 “Working with Vectors and Matrices” 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. Understanding Data Types
  2. Working with Vectors and Matrices
  3. Lists and Data Frames
← Back to R Academy