With dplyr
:
df $ Labels <- cut(df$Variable, breaks = c(0,5, 9))
df %>%
group_by(Labels) %>%
summarise(Mean = mean(Shap), N = n())
# A tibble: 2 x 3
Labels Mean N
<fct> <dbl> <int>
1 (0,5] 0.218 8
2 (5,9] 0.244 7
Data:
df <- structure(list(Variable = c(1L, 6L, 7L, 5L, 9L, 9L, 2L, 9L, 5L,
5L, 1L, 4L, 5L, 8L, 6L), Shap = c(0.1, 0.5, 0.3, 0.4, 0.1, 0.25,
0.24, 0.23, 0.22, 0.21, 0.2, 0.19, 0.18, 0.17, 0.16)), class = "data.frame", row.names = c(NA,
-15L))