Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

mutate

Mutate a data frame by adding new or replacing existing columns.


Description

This function is very similar to transform but it executes the transformations iteratively so that later transformations can use the columns created by earlier transformations. Like transform, unnamed components are silently dropped.

Usage

mutate(.data, ...)

Arguments

.data

the data frame to transform

...

named parameters giving definitions of new columns.

Details

Mutate seems to be considerably faster than transform for large data frames.

See Also

subset, summarise, arrange. For another somewhat different approach to solving the same problem, see within.

Examples

# Examples from transform
mutate(airquality, Ozone = -Ozone)
mutate(airquality, new = -Ozone, Temp = (Temp - 32) / 1.8)

# Things transform can't do
mutate(airquality, Temp = (Temp - 32) / 1.8, OzT = Ozone / Temp)

# mutate is rather faster than transform
system.time(transform(baseball, avg_ab = ab / g))
system.time(mutate(baseball, avg_ab = ab / g))

plyr

Tools for Splitting, Applying and Combining Data

v1.8.6
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.