# Newly created variables are available immediately
a = as.data.table(mtcars)
copy(a) %>% mutate(cyl2 = cyl * 2)
a
# change forever
a %>% mutate(cyl2 = cyl * 2)
a
# You can also use mutate() to remove variables and
# modify existing variables
a %>% mutate(
mpg = NULL,
disp = disp * 0.0163871 # convert to litres
)
a %>% transmute(cyl,one = 1)
a
iris[3:8,] %>%
as.data.table() %>%
mutate_when(Petal.Width == .2,
one = 1,Sepal.Length=2)
iris[3:8,] %>%
as.data.table() %>%
mutate_vars("Pe",scale)
Run the code above in your browser using DataLab