Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Indexing | Vectors
course content

Contenido del Curso

R Introduction: Part I

IndexingIndexing

Great! You now understand how to create a vector and how to assign names to its values.

To access a specific element or elements within a vector, you can utilize indices. The index of the first element is 1, the second element is 2, and so on. To retrieve the n-th element from a vector vec, the syntax is vec[n]. Moreover, if the vector elements have assigned names, you can extract the values by their names by enclosing the name in quotes and square brackets.

Now, let’s revisit the grades example.

SubjectGrade
Math80
Physics75
English95
Literature100

We’ll extract the grade for Math and the grade for Literature.

It’s also possible to access multiple elements simultaneously.

Tarea

Continuing from the previous exercise, you have a vector named prices with each price assigned to a corresponding item name.

  1. Retrieve the price of 'Armchair' using its name rather than its index.
  2. Retrieve the prices for both the 'Dining table' and 'Dining chair' using their indices.

¿Todo estuvo claro?

Sección 2. Capítulo 8
toggle bottom row
course content

Contenido del Curso

R Introduction: Part I

IndexingIndexing

Great! You now understand how to create a vector and how to assign names to its values.

To access a specific element or elements within a vector, you can utilize indices. The index of the first element is 1, the second element is 2, and so on. To retrieve the n-th element from a vector vec, the syntax is vec[n]. Moreover, if the vector elements have assigned names, you can extract the values by their names by enclosing the name in quotes and square brackets.

Now, let’s revisit the grades example.

SubjectGrade
Math80
Physics75
English95
Literature100

We’ll extract the grade for Math and the grade for Literature.

It’s also possible to access multiple elements simultaneously.

Tarea

Continuing from the previous exercise, you have a vector named prices with each price assigned to a corresponding item name.

  1. Retrieve the price of 'Armchair' using its name rather than its index.
  2. Retrieve the prices for both the 'Dining table' and 'Dining chair' using their indices.

¿Todo estuvo claro?

Sección 2. Capítulo 8
toggle bottom row
some-alt