I have created a function which uses 2 variables to do grouping and uses third variable to create min and max for each groups. But the min and max function gives wrong output. It gives the minimum and maximum for entire dataset and not for each group.
myfunction= function(x,a,b,column) {
temp=group_by(x,x[[a]],x[[b]])
Score=summarise(temp,Totals=n(),Mnscore=min(x[[c]]),Mxscore=max(x[[c]]))
return(Score)
}
myfunction(dataset,"a","b","c")
Actual Results:
a b Totals Min Max
1 1 10 15 50
1 2 20 15 50
1 3 30 15 50
Expected results:
a b Totals Min Max
1 1 10 20 48
1 2 20 21 49
1 3 30 15 50