course content

Course Content

R Introduction: Part I

DeletingDeleting

Since you've learned how to add elements to a vector, it's only natural to learn how to remove them as well. Everything builds up to this.

To remove an element from a vector, use the - sign before the index of the element you wish to remove. Remember, this action doesn't directly overwrite your vector, so reassignment will typically be necessary. To remove multiple elements, you can provide a vector of indices after the - sign. For instance, to remove the third element from the grades vector, the operation would look like this:

Similarly, to eliminate the second and fourth elements from the initial grades vector, you would proceed as follows:

Note

Keep in mind that the operations shown in the examples will not alter the original vectors permanently. To save the changes, you need to reassign the result to the same vector (or to a new one, if needed).

Task

From the previous task you have the prices vector with the prices of 6 items. Your task is:

  1. Remove the 'Dining chair' item from the prices vector. This item is fourth in the vector. Save the changes by reassignment.
  2. Display the modified prices vector.

Everything was clear?

Section 2. Chapter 10
toggle bottom row