Course Content

R Introduction: Part II

## R Introduction: Part II

# Transposing

Good! Matrices are widely used in math, starting with different geometrical transformations, and ending with neural networks (yes, matrices are commonly used in AI).

What if we have a matrix and want to 'rotate' it? (or vice versa)?

In math, this operation is called transposing. It swaps columns with rows. In R this operation is implemented under `t()`

function. This function receives the matrix you want to transpose as the parameter. For example,

`# Initial matrix m <- matrix(1:6, nrow = 2) m # Output initial matrix # Output transposed matrix t(m)`

As you can see, the initial matrix was 2x3 (2 rows and 3 columns), and the transposed is 3x2.

Task

Given the matrix from the previous chapter.

- Assign this matrix to the
`m`

variable. - Output the transposed
`m`

matrix.

Task

Given the matrix from the previous chapter.

- Assign this matrix to the
`m`

variable. - Output the transposed
`m`

matrix.

Everything was clear?

# Transposing

Good! Matrices are widely used in math, starting with different geometrical transformations, and ending with neural networks (yes, matrices are commonly used in AI).

What if we have a matrix and want to 'rotate' it? (or vice versa)?

In math, this operation is called transposing. It swaps columns with rows. In R this operation is implemented under `t()`

function. This function receives the matrix you want to transpose as the parameter. For example,

`# Initial matrix m <- matrix(1:6, nrow = 2) m # Output initial matrix # Output transposed matrix t(m)`

As you can see, the initial matrix was 2x3 (2 rows and 3 columns), and the transposed is 3x2.

Task

Given the matrix from the previous chapter.

- Assign this matrix to the
`m`

variable. - Output the transposed
`m`

matrix.

Task

Given the matrix from the previous chapter.

- Assign this matrix to the
`m`

variable. - Output the transposed
`m`

matrix.

Everything was clear?

# Transposing

Good! Matrices are widely used in math, starting with different geometrical transformations, and ending with neural networks (yes, matrices are commonly used in AI).

What if we have a matrix and want to 'rotate' it? (or vice versa)?

In math, this operation is called transposing. It swaps columns with rows. In R this operation is implemented under `t()`

function. This function receives the matrix you want to transpose as the parameter. For example,

`# Initial matrix m <- matrix(1:6, nrow = 2) m # Output initial matrix # Output transposed matrix t(m)`

As you can see, the initial matrix was 2x3 (2 rows and 3 columns), and the transposed is 3x2.

Task

Given the matrix from the previous chapter.

- Assign this matrix to the
`m`

variable. - Output the transposed
`m`

matrix.

Task

Given the matrix from the previous chapter.

- Assign this matrix to the
`m`

variable. - Output the transposed
`m`

matrix.

Everything was clear?

What if we have a matrix and want to 'rotate' it? (or vice versa)?

`t()`

function. This function receives the matrix you want to transpose as the parameter. For example,

As you can see, the initial matrix was 2x3 (2 rows and 3 columns), and the transposed is 3x2.

Task

Given the matrix from the previous chapter.

- Assign this matrix to the
`m`

variable. - Output the transposed
`m`

matrix.