mutate | R Documentation |
With mutate()
you can do 3 things:
Add new columns
Modify existing columns
Delete columns
mutate(
.df,
...,
.by = NULL,
.keep = c("all", "used", "unused", "none"),
.before = NULL,
.after = NULL
)
.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. |
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.