Learn R Programming

dtplyr (version 1.1.0)

mutate.dtplyr_step: Create and modify columns

Description

This is a method for the dplyr mutate() generic. It is translated to the j argument of [.data.table, using := to modify "in place".

Usage

# S3 method for dtplyr_step
mutate(.data, ...)

Arguments

.data
...

<data-masking> Name-value pairs. The name gives the name of the column in the output, and the value should evaluate to a vector.

Examples

Run this code
# NOT RUN {
library(dplyr, warn.conflicts = FALSE)

dt <- lazy_dt(data.frame(x = 1:5, y = 5:1))
dt %>%
  mutate(a = (x + y) / 2, b = sqrt(x^2 + y^2))

# It uses a more sophisticated translation when newly created variables
# are used in the same expression
dt %>%
  mutate(x1 = x + 1, x2 = x1 + 1)
# }

Run the code above in your browser using DataLab