context("test-sample_group_levels")
set.seed(57)
ds_output <- mtcars %>% sample_group_levels(cyl) %>% arrange(drat, wt)
ds_expected <- mtcars %>% filter(cyl == 6) %>% arrange(drat, wt)
test_that("sample_group_levels() works with n=1", {
expect_equal(ds_output, ds_expected)
})
set.seed(57)
ds_output <- mtcars %>% sample_group_levels(cyl, 2) %>% arrange(drat, wt)
ds_expected <- mtcars %>% filter(cyl %in% c(4, 6)) %>% arrange(drat, wt)
test_that("sample_group_levels() works with n=2", {
expect_equal(ds_output, ds_expected)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.