随机抽样 - 图1

    随机抽样 - 图2

    1. sample_n_dt(mtcars, 10)
    2. sample_n_dt(mtcars, 50, replace = TRUE)
    3. sample_frac_dt(mtcars, 0.1)
    4. sample_frac_dt(mtcars, 1.5, replace = TRUE)
    5. sample_dt(mtcars,n=10)
    6. sample_dt(mtcars,prop = 0.1)
    7. # sample by group(s)
    8. iris %>% sample_n_dt(2,by = "Species")
    9. iris %>% sample_frac_dt(.1,by = "Species")
    10. mtcars %>% sample_n_dt(1,by = "cyl,vs")
    11. # equals to
    12. mtcars %>% sample_n_dt(1,by = c("cyl","vs"))