I've been reading and reading, but I cannot understand this NSE vs SE in R. I hope somebody can explain it properly.
df=data.frame(a=1:6,b=7:12,c=13:18,d=rep(c("a","b"),each=3))
This is what I'm used to, and it works:
df %>% group_by(d) %>% mutate(new=sum(a))
Now I'm into new territory, this works, but throws a warning. Can somebody explain to me how I'm to do this if not with group_by_?
var="d"
df %>% group_by_(`var`) %>% mutate(new=sum(a))
Warning message: group_by_() is deprecated. Please use group_by() instead
Now, onto what I'm really trying to do, this just throws an error:
var="d"
var2="a"
df %>% group_by_(`var`) %>% mutate_(new=sum(`var2`))
Error in sum(var2) : invalid 'type' (character) of argument
I'm really trying to understand the fundamentals here... thanks!