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)
Run the code above in your browser using DataLab