I have seen the answer for this question but I have K
groups, each of them with n[k]
elements, and I want to draw for example floor(n[k] * p)
samples from each of these groups.
I was thinking something like this:
df %>%
group_by(my_group) %>%
mutate(
n_samples = floor(n() / 2)
) %>%
sample_n(n_samples)
But that doesn't work because the argument for sample_n
should be the same for every group.
I prefer solutions using dplyr
or at least following the tidyverse
convention.