Pivot data from long to wide
pivot_wider.()
"widens" data, increasing the number of columns and
decreasing the number of rows.
pivot_wider.( .df, names_from = name, values_from = value, id_cols = NULL, names_sep = "_", names_prefix = "", names_glue = NULL, names_sort = FALSE, names_repair = "check_unique", values_fill = NULL, values_fn = NULL )
.df |
A data.frame or data.table |
names_from |
A pair of arguments describing which column (or columns) to get the name of the output column ( |
values_from |
A pair of arguments describing which column (or columns) to get the name of the output column ( |
id_cols |
A set of columns that uniquely identifies each observation.
Defaults to all columns in the data table except for the columns specified in |
names_sep |
the separator between the names of the columns |
names_prefix |
prefix to add to the names of the new columns |
names_glue |
Instead of using |
names_sort |
Should the resulting new columns be sorted |
names_repair |
Treatment of duplicate names. See |
values_fill |
If values are missing, what value should be filled in |
values_fn |
Should the data be aggregated before casting? If the formula doesn't identify a single observation for each cell, then aggregation defaults to length with a message. |
test_df <- data.table( a = rep(c("a", "b", "c"), 2), b = c(rep("x", 3), rep("y", 3)), vals = 1:6 ) test_df %>% pivot_wider.(names_from = b, values_from = vals) test_df %>% pivot_wider.( names_from = b, values_from = vals, names_prefix = "new_" )
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.