Mutate function in R Last Updated : 02 May, 2025 Comments Improve Suggest changes Like Article Like Report 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 RIn 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. R install.packages("dplyr") library(dplyr) 1. mutate() Function in RThe 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. R library(dplyr) d <- data.frame( name = c("Abhi", "Bhavesh", "Chaman", "Dimri"), age = c(7, 5, 9, 16), ht = c(46, NA, NA, 69), school = c("yes", "yes", "no", "no") ) mutate(d, x3 = ht + age) Output:Mutate function in R2. transmute() Function in RThe 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. R library(dplyr) d <- data.frame( name = c("Abhi", "Bhavesh", "Chaman", "Dimri"), age = c(7, 5, 9, 16), ht = c(46, NA, NA, 69), school = c("yes", "yes", "no", "no") ) result <- transmute(d, name = name, age_in_months = age * 12, ht, school) return(result) Output:Mutate function in R3. mutate_all() Function in RThe mutate_all() function is used to apply a transformation to all variables in a data frame simultaneously. R library(dplyr) d <- data.frame( name = c("Abhi", "Bhavesh", "Chaman", "Dimri"), age = c(7, 5, 9, 16), ht = c(46, NA, NA, 69), school = c("yes", "yes", "no", "no") ) d_mutate_all <- d %>% mutate_all(~ ifelse(is.numeric(.), . * 2, .)) return(d_mutate_all) Output:Mutate function in R4. mutate_at() Function in RThe 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. R library(dplyr) d <- data.frame( name = c("Abhi", "Bhavesh", "Chaman", "Dimri"), age = c(7, 5, 9, 16), ht = c(46, NA, NA, 69), school = c("yes", "yes", "no", "no") ) d_mutate_at <- d %>% mutate_at(vars(age), ~ .^2) print(d_mutate_at) Output:Mutate function in R5. mutate_if() Function in RThe 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. R library(dplyr) d <- data.frame( name = c("Abhi", "Bhavesh", "Chaman", "Dimri"), age = c(7, 5, 9, 16), ht = c(46, NA, NA, 69), school = c("yes", "yes", "no", "no") ) d_mutate_if <- d %>% mutate_if(is.numeric, ~ . * 2) return(d_mutate_if) Output:Mutate function in RIn 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 More infoAdvertise with us Next Article Mutate function in R N nidhi_biet Follow Improve Article Tags : R Language R DataFrame-Function Similar Reads Outer() Function in R A flexible tool for working with matrices and vectors in R is the outer() function. It enables you to create a new matrix or array by applying a function to every conceivable combination of the items from two input vectors. outer() function in R Programming Language is used to apply a function to tw 3 min read map() Function in R In R Programming Language the Map function is a very useful function used for element-wise operations across vectors or lists. This article will help show how to use it with multiple code examples. Map Function in RThe Map function in R belongs to the family of apply functions, designed to make oper 3 min read parse() Function in R The parse() function in R programming language is used to return the parsed but unevaluated expression of a given expression in an expression, a âlistâ of calls. Also, this function converts an R object of the character class to an R object of the expression class. Syntax: parse(file = "",  n = NULL 2 min read as.numeric() Function in R The as.numeric() function in R is a crucial tool for data manipulation, allowing users to convert data into numeric form, which is essential for performing mathematical operations and statistical analysis. Overview of the as.numeric() FunctionThe as. numeric() function is part of R's base package an 3 min read by() Function in R R has gained popularity for statistical computing and graphics. It provides the means of shifting the raw data into readable final results. in this article, we will discuss what is by() Function in R and how to use this. What is by() Function in R?The by() function is a localized function in R Progr 5 min read sum() function in R sum() function in R Programming Language returns the addition of the values passed as arguments to the function. Syntax: sum(...) Parameters: ...: numeric or complex or logical vectorssum() Function in R ExampleR program to add two numbersHere we will use sum() functions to add two numbers. R a1=c(1 2 min read Unique() Function in R Unique() function in R Programming Language it is used to return a vector, data frame, or array without any duplicate elements/rows. Syntax: unique(x, incomparables, fromLast, nmax, â¦,MARGIN) Parameters: This function accepts some parameters which are illustrated below: x: This parameter is a vector 4 min read Tidyverse Functions in R Tidyverse is a collection of R packages designed to make data analysis easier, more intuitive, and efficient. Among the various packages within Tidyverse, several key functions stand out for their versatility and usefulness in data manipulation tasks. In this article, we'll explore some of the most 4 min read View Function in R The View() function in R is a built-in function that allows users to view the contents of data structures interactively in a spreadsheet-like format. When we use the View() function, it opens a separate window or tab (depending on your R environment) displaying the data in a table format, making it 2 min read which() Function in R which() function in R Programming Language is used to return the position of the specified values in the logical vector. Syntax: which(x, arr.ind, useNames) Parameters: This function accepts some parameters which are illustrated below: X: This is the specified input logical vectorArr.ind: This param 3 min read Like