I am struggling to mix referencing column names using parameters and directly from the dataframe. please help me correct the second function to return the same result as the first
install.packages("dplyr", version = "0.5.0")`
library(dplyr)
df <- data.frame(year = 2010:2015, GVA = 1:6)
f <- function(df) {
df %>%
mutate(indexGVA = GVA/max(ifelse(year == 2010, GVA, 0)) * 100)
}
f(df)
g <- function(df, val = NULL) {
df %>%
mutate_(indexGVA = ~val/max(ifelse(year == 2010, val, 0)) * 100)
}
g(df, val = "GVA")