Uncount a data.table
uncount(.df, weights, .remove = TRUE, .id = NULL)
A data.frame or data.table
A column containing the weights to uncount by
If TRUE removes the selected weights
column
A string name for a new column containing a unique identifier for the newly uncounted rows.
df <- data.table(x = c("a", "b"), n = c(1, 2))
uncount(df, n)
#> # A tidytable: 3 × 1
#> x
#> <chr>
#> 1 a
#> 2 b
#> 3 b
uncount(df, n, .id = "id")
#> # A tidytable: 3 × 2
#> x id
#> <chr> <int>
#> 1 a 1
#> 2 b 1
#> 3 b 2