You are almost there, just a little syntax issues
mydata <- data.frame(a = 1:10, b = 2:11, c = 3:12, d = 4:13, e = 5:14)
newcol <- function(df, x) {
df[[paste(x, "_fit", sep='')]] <- df[[x]] * 2
df
}
newcol(mydata, "a")
#> a b c d e a_fit
#> 1 1 2 3 4 5 2
#> 2 2 3 4 5 6 4
#> 3 3 4 5 6 7 6
#> 4 4 5 6 7 8 8
#> 5 5 6 7 8 9 10
#> 6 6 7 8 9 10 12
#> 7 7 8 9 10 11 14
#> 8 8 9 10 11 12 16
#> 9 9 10 11 12 13 18
#> 10 10 11 12 13 14 20
Created on 2019-11-05 by the reprex package (v0.3.0.9000)
Or if you are looking for the tidyverse way to do it, this could work
library(dplyr)
mydata <- data.frame(a = 1:10, b = 2:11, c = 3:12, d = 4:13, e = 5:14)
mydata %>%
mutate_all(list(fit = ~ . * 2))
#> a b c d e a_fit b_fit c_fit d_fit e_fit
#> 1 1 2 3 4 5 2 4 6 8 10
#> 2 2 3 4 5 6 4 6 8 10 12
#> 3 3 4 5 6 7 6 8 10 12 14
#> 4 4 5 6 7 8 8 10 12 14 16
#> 5 5 6 7 8 9 10 12 14 16 18
#> 6 6 7 8 9 10 12 14 16 18 20
#> 7 7 8 9 10 11 14 16 18 20 22
#> 8 8 9 10 11 12 16 18 20 22 24
#> 9 9 10 11 12 13 18 20 22 24 26
#> 10 10 11 12 13 14 20 22 24 26 28