Modify Columns
Existing columns can be modified by assigning new values to desired columns.
Syntax:
mutate(dataframe,column_name=new_values)
Parameters: It will take two parameters
- dataframe is the input dataframe
- column_name is the name of the column to modify the values
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) # Modify FirstName, Salary column d < - mutate (d, FirstName= c ( "Mahesh" , "Jignesh" , "Ria" , "Tanya" ), Salary= c (60000, 30000, 50000, 75000)) print (d) |
FirstName Salary Expenses Suresh 50000 20000 Ramesh 60000 15000 Tanya 70000 30000 Sujata 80000 25000 FirstName Salary Expenses Mahesh 60000 20000 Jignesh 30000 15000 Ria 50000 30000 Tanya 75000 25000
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.