According to the dplyr
help file the sample_n
function samples a fixed number per group.
When I run the following code I expect two samples per tobgp and alcgp combination, so 32 (4*4*2) lines in total. However only two lines are returned.
by_tobgp_alcgp <- esoph %>% group_by(tobgp,alcgp)
sample_n(by_tobgp_alcgp , 2)
# Source: local data frame [2 x 5]
# Groups: tobgp, alcgp
#
# agegp alcgp tobgp ncases ncontrols
# 10 25-34 80-119 10-19 0 1
# 50 55-64 0-39g/day 30+ 4 6
Is this correct? Is there an alternative way to achieve this using dplyr
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…