R data.table - sample by group with different sampling proportion
问题 I would like to efficiently make a random sample by group from a data.table , but it should be possible to sample a different proportion for each group. If I wanted to sample fraction sampling_fraction from each group, i could get inspired by this question and related answer to do something like: DT = data.table(a = sample(1:2), b = sample(1:1000,20)) group_sampler <- function(data, group_col, sample_fraction){ # this function samples sample_fraction <0,1> from each group in the data.table #