uncount | R Documentation |
Performs the opposite operation to dplyr::count()
, duplicating rows
according to a weighting variable (or expression).
uncount(data, weights, ..., .remove = TRUE, .id = NULL)
data |
A data frame, tibble, or grouped tibble. |
weights |
A vector of weights. Evaluated in the context of |
... |
Additional arguments passed on to methods. |
.remove |
If |
.id |
Supply a string to create a new variable which gives a unique identifier for each created row. |
df <- tibble(x = c("a", "b"), n = c(1, 2))
uncount(df, n)
uncount(df, n, .id = "id")
# You can also use constants
uncount(df, 2)
# Or expressions
uncount(df, 2 / n)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.