Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Understanding Matrices | Section
Practice
Projects
Quizzes & Challenges
Вікторини
Challenges
/
Essential R Programming for Absolute Beginners - 1768563985826

bookUnderstanding Matrices

Note
Definition

A matrix is a two-dimensional data structure where each element is identified by its row and column position, and elements must be of the same data type.

In R, matrices can be created in different ways. The most common are by merging vectors as rows or by merging them as columns.

Creating Matrix from Rows

You can create a matrix by combining vectors as rows with rbind() function.

Example

12345
row_1 = c(1, 2, 3) row_2 = c(4, 5, 6) # Bind rows into a matrix rbind(row_1, row_2)
copy

This produces a matrix with two rows and three columns.

Creating Matrix from Columns

Alternatively, you can create a matrix by combining vectors as columns with cbind() function.

Example

12345
col_1 = c(1, 2, 3) col_2 = c(4, 5, 6) # Bind columns into a matrix cbind(col_1, col_2)
copy

This produces a matrix with three rows and two columns.

Завдання

Swipe to start coding

  1. Create two vectors:
    • a with integers from 1 to 4;
    • b with integers from 5 to 8.
      Use the colon (:) sign syntax for a range.
  2. Create and output matrix by merging a and b as rows.
  3. Create and output matrix by merging a and b as columns.

Рішення

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 27
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

close

bookUnderstanding Matrices

Свайпніть щоб показати меню

Note
Definition

A matrix is a two-dimensional data structure where each element is identified by its row and column position, and elements must be of the same data type.

In R, matrices can be created in different ways. The most common are by merging vectors as rows or by merging them as columns.

Creating Matrix from Rows

You can create a matrix by combining vectors as rows with rbind() function.

Example

12345
row_1 = c(1, 2, 3) row_2 = c(4, 5, 6) # Bind rows into a matrix rbind(row_1, row_2)
copy

This produces a matrix with two rows and three columns.

Creating Matrix from Columns

Alternatively, you can create a matrix by combining vectors as columns with cbind() function.

Example

12345
col_1 = c(1, 2, 3) col_2 = c(4, 5, 6) # Bind columns into a matrix cbind(col_1, col_2)
copy

This produces a matrix with three rows and two columns.

Завдання

Swipe to start coding

  1. Create two vectors:
    • a with integers from 1 to 4;
    • b with integers from 5 to 8.
      Use the colon (:) sign syntax for a range.
  2. Create and output matrix by merging a and b as rows.
  3. Create and output matrix by merging a and b as columns.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 27
single

single

some-alt