Groups a dataframe by the specified feature, selects n of these groups and discards the rest. Returned dataframe is ungrouped.

rand_n_groups(df, group_var, n)

Arguments

df

A data frame or data frame like object recognized by dplyr

group_var

Feature to group by. Uses NSE like dplyr verbs.

n

Number of groups to take. If there are fewer than n groups, uses the

Value

Dataframe with n random groups selected according to specified grouping feature.

Examples

rand_n_groups(mtcars, cyl, 2)
#> Error in (function (x) { x})(group_quo): object 'group_quo' not found