Description Usage Arguments See Also Examples
Sample a dataframe for n obs and returns full dataframe if n > nrow
1 | sample_all_or_n(data, n, replace = FALSE, weight = NULL)
|
data |
A dataframe or tibble. |
n |
Number of rows to sample. If n is greater than the row count, the dataframe will be returned unchanged. |
replace |
Sample with or without replacement? |
weight |
Sampling weights. This must evaluate to a vector of non-negative numbers the same length as the input. Weights are automatically standardised to sum to 1. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | library(tidyverse)
test_data <-
tibble(
Group = sample(c("Apple", "Pear"), size = 10, replace = TRUE),
A = sample(c(NA_integer_, 1:3), size = 10, replace = TRUE),
B = sample(c(NA_integer_, 4:6), size = 10, replace = TRUE)
)
# Sample less than row count
sample_all_or_n(data = test_data,
n = 5)
# When n is greater than row count, the dataframe is returned unchanged
sample_all_or_n(data = test_data,
n = 11)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.