Зміст курсу

R Introduction: Part II

## R Introduction: Part II

# What is a Matrix?

A matrix is a two-dimensional data structure in R, which means that every matrix element can be characterized by its position among rows and columns. Matrices in R can contain data of only one type, i.e., a matrix can not contain numbers and text simultaneously.

There are several ways to create a matrix in R. On one side, you can 'merge' two rows; on the other, you can 'merge' two columns. Let's consider each method separately. The first one is the `rbind()`

function. Function name comes from **R**ows **Bind** - this function connects vectors as rows.

As you can see, this matrix has two rows and three columns (since each row has three values).
Another way - is to use `cbind()`

function. Likewise, the previous function, name of this function comes from **C**olumns **Bind**. Let's look at the example.

As you can see, this matrix has two columns and three rows (since each column has three values).

Завдання

Practice creating matrices by yourself using both methods!

- Create two vectors:
`a`

with integers from`1`

to`4`

, and`b`

with integers from`5`

to`8`

using the colon`:`

sign. - Create and output matrix by merging
`a`

and`b`

as**rows**. - Create and output matrix by merging
`a`

and`b`

as**columns**.

_{Once you've completed this task, click the Submit Task button below the code to check your solution.}

Завдання

Practice creating matrices by yourself using both methods!

- Create two vectors:
`a`

with integers from`1`

to`4`

, and`b`

with integers from`5`

to`8`

using the colon`:`

sign. - Create and output matrix by merging
`a`

and`b`

as**rows**. - Create and output matrix by merging
`a`

and`b`

as**columns**.

_{Once you've completed this task, click the Submit Task button below the code to check your solution.}

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

# What is a Matrix?

A matrix is a two-dimensional data structure in R, which means that every matrix element can be characterized by its position among rows and columns. Matrices in R can contain data of only one type, i.e., a matrix can not contain numbers and text simultaneously.

There are several ways to create a matrix in R. On one side, you can 'merge' two rows; on the other, you can 'merge' two columns. Let's consider each method separately. The first one is the `rbind()`

function. Function name comes from **R**ows **Bind** - this function connects vectors as rows.

As you can see, this matrix has two rows and three columns (since each row has three values).
Another way - is to use `cbind()`

function. Likewise, the previous function, name of this function comes from **C**olumns **Bind**. Let's look at the example.

As you can see, this matrix has two columns and three rows (since each column has three values).

Завдання

Practice creating matrices by yourself using both methods!

- Create two vectors:
`a`

with integers from`1`

to`4`

, and`b`

with integers from`5`

to`8`

using the colon`:`

sign. - Create and output matrix by merging
`a`

and`b`

as**rows**. - Create and output matrix by merging
`a`

and`b`

as**columns**.

_{Once you've completed this task, click the Submit Task button below the code to check your solution.}

Завдання

Practice creating matrices by yourself using both methods!

- Create two vectors:
`a`

with integers from`1`

to`4`

, and`b`

with integers from`5`

to`8`

using the colon`:`

sign. - Create and output matrix by merging
`a`

and`b`

as**rows**. - Create and output matrix by merging
`a`

and`b`

as**columns**.

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

# What is a Matrix?

A matrix is a two-dimensional data structure in R, which means that every matrix element can be characterized by its position among rows and columns. Matrices in R can contain data of only one type, i.e., a matrix can not contain numbers and text simultaneously.

There are several ways to create a matrix in R. On one side, you can 'merge' two rows; on the other, you can 'merge' two columns. Let's consider each method separately. The first one is the `rbind()`

function. Function name comes from **R**ows **Bind** - this function connects vectors as rows.

As you can see, this matrix has two rows and three columns (since each row has three values).
Another way - is to use `cbind()`

function. Likewise, the previous function, name of this function comes from **C**olumns **Bind**. Let's look at the example.

As you can see, this matrix has two columns and three rows (since each column has three values).

Завдання

Practice creating matrices by yourself using both methods!

- Create two vectors:
`a`

with integers from`1`

to`4`

, and`b`

with integers from`5`

to`8`

using the colon`:`

sign. - Create and output matrix by merging
`a`

and`b`

as**rows**. - Create and output matrix by merging
`a`

and`b`

as**columns**.

Завдання

Practice creating matrices by yourself using both methods!

- Create two vectors:
`a`

with integers from`1`

to`4`

, and`b`

with integers from`5`

to`8`

using the colon`:`

sign. - Create and output matrix by merging
`a`

and`b`

as**rows**. - Create and output matrix by merging
`a`

and`b`

as**columns**.

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

`rbind()`

function. Function name comes from **R**ows **Bind** - this function connects vectors as rows.

`cbind()`

function. Likewise, the previous function, name of this function comes from **C**olumns **Bind**. Let's look at the example.

As you can see, this matrix has two columns and three rows (since each column has three values).

Завдання

Practice creating matrices by yourself using both methods!

- Create two vectors:
`a`

with integers from`1`

to`4`

, and`b`

with integers from`5`

to`8`

using the colon`:`

sign. - Create and output matrix by merging
`a`

and`b`

as**rows**. - Create and output matrix by merging
`a`

and`b`

as**columns**.