Converts a vintages dataset from long format to wide format, optionally
grouping by id
if present. The wide format uses one column per unique
value of the names_from
parameter, with observation dates (time
) as
rows and values (value
) as cell contents.
Value
If an id
column is present, the function returns a named list of
wide-format data frames, one for each unique id
. Otherwise, it returns a
single wide-format data frame.
Examples
# Example wide-format data
long_data <- dplyr::filter(reviser::gdp, id=="US")
# Convert to wide format
wide_data <- vintages_wide(long_data)
# Example list of wide-format data frames
wide_list <- list(
A = wide_data$US,
B = wide_data$US
)
# Convert list to long format
long_data1 <- vintages_long(wide_data, names_to = "pub_date")
long_data2 <- vintages_long(wide_list, names_to = "pub_date")