As a part of a function I'm trying to create a dataframe and I want to name one of the columns after a variable. The below is some dummy data and is the part that I'm stuck on.
library(tidyverse)
graph <- data.frame(brand = rep(c("A","B","C"), each = 3),
week_commencing = rep(as.Date(c('2020-03-01', '2020-04-01', '2020-05-01')), times = 3),
sessions = sample(1000:2000,9),
conv_rate = runif(9,0,1))
website = "A"
metric = "sessions"
graph %>%
filter(brand == (!!website)) %>%
group_by(brand) %>%
summarise(metric = max(get(metric)),
week_commencing = min(week_commencing),
lab = "This Year")
In the summarise function call I want the column name metric to be called sessions, I've tried using get(metric) and (!!metric) as part of the naming of the column but it doesn't work.
Is this even possible to do in R? Any help would be appreciated.