mutate {tidytable} | R Documentation |
Add/modify/delete columns
Description
With mutate()
you can do 3 things:
Add new columns
Modify existing columns
Delete columns
Usage
mutate(
.df,
...,
.by = NULL,
.keep = c("all", "used", "unused", "none"),
.before = NULL,
.after = NULL
)
Arguments
.df |
A data.frame or data.table |
... |
Columns to add/modify |
.by |
Columns to group by |
.keep |
experimental:
This is an experimental argument that allows you to control which columns
from
|
.before , .after |
Optionally indicate where new columns should be placed. Defaults to the right side of the data frame. |
Examples
df <- data.table(
a = 1:3,
b = 4:6,
c = c("a", "a", "b")
)
df %>%
mutate(double_a = a * 2,
a_plus_b = a + b)
df %>%
mutate(double_a = a * 2,
avg_a = mean(a),
.by = c)
df %>%
mutate(double_a = a * 2, .keep = "used")
df %>%
mutate(double_a = a * 2, .after = a)
[Package tidytable version 0.11.1 Index]