Remove a column by using column name

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

Syntax:

select(dataframe,-column_name)

Where, dataframe is the input dataframe and column_name is the name of the column to be removed.

Example: R program to remove a column

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 column
print(select(data1,-name))
  
# remove id column
print(select(data1,-id))


Output:

How to Remove a Column by name and index using Dplyr Package in R

In this article, we are going to remove columns by name and index in the R programming language using dplyr package.

Dataset in use:

Similar Reads

Remove a column by using column name

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

Remove multiple columns by using column name

...

Remove a column by using column index

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

Remove multiple columns by using column index

...

Contact Us