dt_pivot_wider() "widens" data, increasing the number of columns and decreasing the number of rows. The inverse transformation is dt_pivot_longer(). Syntax based on the tidyr equivalents.

dt_pivot_wider(dt_, id_cols = NULL, names_from, names_sep = "_",
values_from, drop = TRUE)

## Arguments

dt_ the data table to widen A set of columns that uniquely identifies each observation. Defaults to all columns in the data table except for the columns specified in names_from and values_from. Typically used when you have additional variables that is directly related. A pair of arguments describing which column (or columns) to get the name of the output column (name_from), and which column (or columns) to get the cell values from (values_from). the separator between the names of the columns A pair of arguments describing which column (or columns) to get the name of the output column (name_from), and which column (or columns) to get the cell values from (values_from). When FALSE, will cast by including all missing combinations. When TRUE, it is drop missing combination. c(FALSE, TRUE) will only include all missing combinations of formula LHS; c(TRUE, FALSE) will only include all missing combinations of formula RHS.

## Examples


library(data.table)
example_dt <- data.table(z = rep(c("a", "b", "c"), 2),
stuff = c(rep("x", 3), rep("y", 3)),
things = 1:6)

dt_pivot_wider(example_dt, names_from = stuff, values_from = things)#>    z x y
#> 1: a 1 4
#> 2: b 2 5
#> 3: c 3 6