Delete Columns

Columns can be deleted from the existing data frame by setting the value of the desired column to NULL.

Syntax:

mutate(dataframe,columns = NULL)

Parameter:

  • It takes only one parameter that is column name to be deleted

Example:

R




library(dplyr)
  
# Create a data frame
d <- data.frame( FirstName = c("Suresh","Ramesh","Tanya","Sujata"),
                 Salary = c(50000,60000,70000,80000),
                 Expenses = c(20000,15000,30000,25000))
  
print(d)
  
# Delete Expenses column
d <- mutate(d,Expenses = NULL)
  
print(d)


Output:

FirstName  Salary Expenses

Suresh     50000  20000
Ramesh     60000  15000
Tanya      70000  30000
Sujata     80000  25000

FirstName  Salary 

Suresh     50000  
Ramesh     60000  
Tanya      70000
Sujata     80000 
 

Create, modify, and delete columns using dplyr package in R

In this article, we will discuss mutate function present in dplyr package in R Programming Language to create, modify, and delete columns of a dataframe.

Similar Reads

Create new columns

Columns can be inserted either by appending a new column or using existing columns to evaluate a new column. By default, columns are added to the far right. Although columns can be added to any desired position using .before and .after arguments...

Delete Columns

...

Modify Columns

Columns can be deleted from the existing data frame by setting the value of the desired column to NULL....