| sample_n_of | R Documentation |
Randomly sample data from n sub-groups of data
sample_n_of(data, size, ...)
data |
a dataframe |
size |
number of groups to sample |
... |
variables to group by |
the data from subgroups
sample_data <- tibble::tibble(
letter = rep(letters, 5),
color = rep(c("red", "green", "yellow", "orange", "blue"), 26),
value = rnorm(26 * 5)
)
# data from two letters
sample_data %>%
sample_n_of(2, letter)
# data from two colors
sample_data %>%
sample_n_of(2, color)
# data from 10 letter-colors pairs
sample_data %>%
sample_n_of(10, letter, color)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.