dt_uncount.Rd
Uncount a counted data table
dt_uncount(dt_, weights, .remove = TRUE, .id = NULL)
the data table to uncount
the counts for each
should the weights variable be removed?
an optional new id variable, providing a unique id for each row
A data.table with a row for each uncounted column.
library(data.table)
dt_count <- data.table(
x = LETTERS[1:3],
w = c(2, 1, 4)
)
uncount <- dt_uncount(dt_count, w, .id = "id")
uncount[] # note that `[]` forces the printing
#> x .id
#> <char> <int>
#> 1: A 1
#> 2: A 2
#> 3: B 3
#> 4: C 4
#> 5: C 5
#> 6: C 6
#> 7: C 7