Drop multiple columns by using the column name

We can remove a column with select() method by its column name

Syntax:

select(dataframe,-c(column_name1,column_name2,.,column_name n)

Where, dataframe is the input dataframe and -c(column_names) is the collection of names of the column to be removed.

Example: R program to remove multiple columns by column name

R




# load the library
library(dplyr)
  
# create dataframe with 3 columns id,
# name and address
data1=data.frame(id=c(1,2,3,4,5,6,7,1,4,2),
                   
                 name=c('sravan','ojaswi','bobby',
                        'gnanesh','rohith','pinkey',
                        'dhanush','sravan','gnanesh',
                        'ojaswi'),
                   
                 address=c('hyd','hyd','ponnur','tenali',
                           'vijayawada','vijayawada','guntur',
                           'hyd','tenali','hyd'))
  
# remove name and id  column
print(select(data1,-c(id,name)))
  
# remove name and address column
print(select(data1,-c(address,name)))
  
# remove all column
print(select(data1,-c(address,name,id)))


Output:

Drop multiple columns using Dplyr package in R

In this article, we will discuss how to drop multiple columns using dplyr package in R programming language.

Dataset in use:

Similar Reads

Drop multiple columns by using the column name

We can remove a column with select() method by its column name...

Drop multiple columns by using column index

...

Drop column which contains a value or matches a pattern

We can remove a column with select() method by its column index/position. Index starts with 1....

Remove column which starts with or ends with certain character

...

Drop column name with Regular Expression

Let’s see how to remove the column that contains the character/string....