Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Matrix Indexation | Matrices
R Introduction: Part II
course content

Contenido del Curso

R Introduction: Part II

R Introduction: Part II

1. Matrices
2. Data Frames
3. Lists

Matrix Indexation

Good. Now you know how to create a matrix in several ways. Let's work with already created objects. First, we need to learn how to access certain matrix elements.

Back to the Vectors section, you should remember that indexation in R starts with 1. Since the matrix is a two-dimensional structure, we need to refer to two positions: among rows and columns. Like in vectors, you need to use square brackets and put two integers (the first is the row number, the second is the column number) divided by a comma. For example, let's extract element 5 (row 2, column 2) and 3 (row 1, column 3) from the matrix below.

Also you can extract multiple rows and/or columns at once. Pass vector of indices instead of a single index. For example, we can extract the 2nd and 3rd columns for the 3rd row.

If you want to extract an entire row/column, do not set an index for the remaining part. For example, let's pull the first row and the third column.

Tarea

Given matrix named m.

Your tasks are:

  1. Extract the element 12.
  2. Extract the elements 4 6.
  3. Extract the third column.

Tarea

Given matrix named m.

Your tasks are:

  1. Extract the element 12.
  2. Extract the elements 4 6.
  3. Extract the third column.

¿Todo estuvo claro?

Sección 1. Capítulo 4
toggle bottom row

Matrix Indexation

Good. Now you know how to create a matrix in several ways. Let's work with already created objects. First, we need to learn how to access certain matrix elements.

Back to the Vectors section, you should remember that indexation in R starts with 1. Since the matrix is a two-dimensional structure, we need to refer to two positions: among rows and columns. Like in vectors, you need to use square brackets and put two integers (the first is the row number, the second is the column number) divided by a comma. For example, let's extract element 5 (row 2, column 2) and 3 (row 1, column 3) from the matrix below.

Also you can extract multiple rows and/or columns at once. Pass vector of indices instead of a single index. For example, we can extract the 2nd and 3rd columns for the 3rd row.

If you want to extract an entire row/column, do not set an index for the remaining part. For example, let's pull the first row and the third column.

Tarea

Given matrix named m.

Your tasks are:

  1. Extract the element 12.
  2. Extract the elements 4 6.
  3. Extract the third column.

Tarea

Given matrix named m.

Your tasks are:

  1. Extract the element 12.
  2. Extract the elements 4 6.
  3. Extract the third column.

¿Todo estuvo claro?

Sección 1. Capítulo 4
toggle bottom row

Matrix Indexation

Good. Now you know how to create a matrix in several ways. Let's work with already created objects. First, we need to learn how to access certain matrix elements.

Back to the Vectors section, you should remember that indexation in R starts with 1. Since the matrix is a two-dimensional structure, we need to refer to two positions: among rows and columns. Like in vectors, you need to use square brackets and put two integers (the first is the row number, the second is the column number) divided by a comma. For example, let's extract element 5 (row 2, column 2) and 3 (row 1, column 3) from the matrix below.

Also you can extract multiple rows and/or columns at once. Pass vector of indices instead of a single index. For example, we can extract the 2nd and 3rd columns for the 3rd row.

If you want to extract an entire row/column, do not set an index for the remaining part. For example, let's pull the first row and the third column.

Tarea

Given matrix named m.

Your tasks are:

  1. Extract the element 12.
  2. Extract the elements 4 6.
  3. Extract the third column.

Tarea

Given matrix named m.

Your tasks are:

  1. Extract the element 12.
  2. Extract the elements 4 6.
  3. Extract the third column.

¿Todo estuvo claro?

Good. Now you know how to create a matrix in several ways. Let's work with already created objects. First, we need to learn how to access certain matrix elements.

Back to the Vectors section, you should remember that indexation in R starts with 1. Since the matrix is a two-dimensional structure, we need to refer to two positions: among rows and columns. Like in vectors, you need to use square brackets and put two integers (the first is the row number, the second is the column number) divided by a comma. For example, let's extract element 5 (row 2, column 2) and 3 (row 1, column 3) from the matrix below.

Also you can extract multiple rows and/or columns at once. Pass vector of indices instead of a single index. For example, we can extract the 2nd and 3rd columns for the 3rd row.

If you want to extract an entire row/column, do not set an index for the remaining part. For example, let's pull the first row and the third column.

Tarea

Given matrix named m.

Your tasks are:

  1. Extract the element 12.
  2. Extract the elements 4 6.
  3. Extract the third column.

Sección 1. Capítulo 4
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt