Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Deleting Vector Elements | Section
Practice
Projects
Quizzes & Challenges
Quiz
Challenges
/
Essential R Programming for Absolute Beginners - 1768563985826

bookDeleting Vector Elements

Elements can be removed from a vector by placing a minus sign (-) before their indices. This creates a new vector without those elements.

Removing a Single Element

You can exclude one element by its index.

Example

12345
grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Remove the third grade (English) grades[-3]
copy

Removing Multiple Elements

Provide a vector of indices to remove more than one element.

Example

12345
grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Remove the second and fourth elements (Physics and Literature) grades[-c(2,4)]
copy

Applying Changes

The changes shown in the examples are temporary. To make them permanent, you must reassign the result to the original (or, if needed, different) variable.

123456789
grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Changes are not applied grades[-3] grades # Changes are applied grades <- grades[-3] grades
copy
Tâche

Swipe to start coding

You have the prices vector with the prices of 6 items. Your task is to:

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

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 19
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

close

bookDeleting Vector Elements

Glissez pour afficher le menu

Elements can be removed from a vector by placing a minus sign (-) before their indices. This creates a new vector without those elements.

Removing a Single Element

You can exclude one element by its index.

Example

12345
grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Remove the third grade (English) grades[-3]
copy

Removing Multiple Elements

Provide a vector of indices to remove more than one element.

Example

12345
grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Remove the second and fourth elements (Physics and Literature) grades[-c(2,4)]
copy

Applying Changes

The changes shown in the examples are temporary. To make them permanent, you must reassign the result to the original (or, if needed, different) variable.

123456789
grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Changes are not applied grades[-3] grades # Changes are applied grades <- grades[-3] grades
copy
Tâche

Swipe to start coding

You have the prices vector with the prices of 6 items. Your task is to:

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

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 19
single

single

some-alt