library(dplyr)
func <- function(data, col){
data <- data %>%
mutate(col = {{col}}*2)
return(data)
}
df <- data.frame(x = c(1:8), y = c("hello", "world", "sun", "winter"))
func(df, x)
x y col
1 1 hello 2
2 2 world 4
3 3 sun 6
4 4 winter 8
5 5 hello 10
6 6 world 12
7 7 sun 14
8 8 winter 16
I want the x column to be updated:
x y
1 2 hello
2 4 world
3 6 sun
4 8 winter
5 10 hello
6 12 world
7 14 sun
8 16 winter
I tried several things with no success, does anybody have any suggestions? Thanks in advance!