I'm trying to create a function where you can pass a data frame and the name of one of the columns. Within the function it should mutate the data frame to create a scaled version of the column you sent. Here's my attempt:
test_scale <- function(outcome, data){
outcome_scaled = paste0(outcome, "_s")
data = data %>% mutate(!!outcome_scaled := scale(as.numeric(outcome)))
print(head(data[, outcome_scaled]))
}
However, this doesn't work since it just prints the text of whatever outcome I pass it.
> test_scale("age", df)
mutate: new variable 'age_s' (character) with one unique value and 0% NA
[1] "age" "age" "age" "age" "age" "age"
How do I get the actual value of outcome
instead of the string text of the outcome variable that's passed?