VOOZH about

URL: https://www.geeksforgeeks.org/r-language/add-new-variables-to-a-data-frame-using-existing-variables-in-r-programming-mutate-function/

⇱ Mutate function in R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Mutate function in R

Last Updated : 15 Jul, 2025

The mutate() function in R Programming Language is used to add new variables in a data frame which are formed by performing operations on existing variables. It can be used by loading the dplyr library.

Syntax:

mutate(x, expr)

Parameters:

  • x: Data Frame
  • expr: operation on variables

Types of mutate() Function in R

In R there are five types of main function for mutate that are describe as below. We will use dplyr package in R for all mutate functions. The dplyr library can be installed using the install.packages() function.

1. mutate() Function in R

The mutate() function in R is used to create new variables or modify existing variables in a data frame without removing any other variables. It allows you to apply transformations or calculations to columns and add the result as new columns or overwrite existing ones.

Output:

👁 mutate
Mutate function in R

2. transmute() Function in R

The transmute() function in R is used to create new variables or modify existing variables in a data frame, while simultaneously dropping the variables that are not part of the result.

Output:

👁 transmutate
Mutate function in R

3. mutate_all() Function in R

The mutate_all() function is used to apply a transformation to all variables in a data frame simultaneously.

Output:

👁 mutate_all
Mutate function in R

4. mutate_at()Function in R

The mutate_at() function in R is used to apply transformations to specific columns in a data frame, based on a condition, such as column names or positions.

Output:

👁 mutate_at
Mutate function in R

5. mutate_if()Function in R

The mutate_if() function in R, part of the dplyr package, is used to apply a transformation to variables in a data frame based on a specific condition. It allows you to selectively apply a mutation only to the variables that satisfy the specified condition.

Output:

👁 mutate_if
Mutate function in R

In this article, we explored how to add new variables to a data frame using existing variables in R Programming, with the help of the mutate() function.

Comment
Article Tags:

Explore