Uncount a data.table

uncount(.df, weights, .remove = TRUE, .id = NULL)

Arguments

.df

A data.frame or data.table

weights

A column containing the weights to uncount by

.remove

If TRUE removes the selected weights column

.id

A string name for a new column containing a unique identifier for the newly uncounted rows.

Examples

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