Hi Please note when i use the below example the code doesnot work for the nesting part. It nests by only single variable instead of two variables can you please help.
d_1<-data.frame(v1=c("a","a","a","b","b","b"),
v2=c("c","c","c","d","d","d"),
M1=c(10,10,10,10,10,10),
M2=c(20,20,20,20,20,20),
M3=c(30,30,30,30,30,30),
M4=c(40,40,40,40,40,40))
group_sum_2<-function(d,group_var)
{
d %>%
group_by(!!!syms(group_var),.add=TRUE)%>%
summarise_if(is.numeric,sum)%>%
group_nest(!!!syms(group_var),.keep=TRUE) # this line does not nest by two variables v1 and v2
}
var_2<-c("v1","v2") # in the nesting part the column v2 is not getting added.
group_sum_2(d_1,var_2)