I would like to generate a table with groups per range, the mean and the count of variables in each group.
I have a data.frame like below:
Variable Shap
1 0.10
6 0.50
7 0.30
5 0.40
9 0.10
9 0.25
2 0.24
9 0.23
5 0.22
5 0.21
1 0.20
4 0.19
5 0.18
8 0.17
6 0.16
And would like to get a dataframe like this
Range Shap_Avg Counts
0-5 0.2175000 8
6-9 0.2442857 7
For grouping and mean I have this code, but I don“t know how I can include the count function
# Group and mean
Group <- data %>%
group_by(Range = cut(Variable, breaks = c(0, 5, 9),
labels = c("0-5", "6-9"))) %>%
summarise(Shap_Avg = mean(Shap))