Deleting 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
12345grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Remove the third grade (English) grades[-3]
Removing Multiple Elements
Provide a vector of indices to remove more than one element.
Example
12345grades <- 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)]
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.
123456789grades <- 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
Swipe to start coding
You have the prices vector with the prices of 6 items. Your task is to:
- Remove the
'Dining chair'item from thepricesvector. This item is the fourth in the vector. Save the changes by reassignment. - Display the modified
pricesvector.
Oplossing
Bedankt voor je feedback!
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Geweldig!
Completion tarief verbeterd naar 2.27
Deleting Vector Elements
Veeg om het menu te tonen
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
12345grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Remove the third grade (English) grades[-3]
Removing Multiple Elements
Provide a vector of indices to remove more than one element.
Example
12345grades <- 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)]
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.
123456789grades <- 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
Swipe to start coding
You have the prices vector with the prices of 6 items. Your task is to:
- Remove the
'Dining chair'item from thepricesvector. This item is the fourth in the vector. Save the changes by reassignment. - Display the modified
pricesvector.
Oplossing
Bedankt voor je feedback!
single