long2wide: Reshape Long API Data to Column-Based Format

Description Usage Arguments Value See Also Examples

View source: R/accessdb.R

Description

This function automatically reshapes long (stacked) raw data from the API (get_data(..., wide = FALSE)) to a wide format where each variable has its own column.

Usage

1
2
3
4
5
6
7
8
9
long2wide(
  data,
  id_cols = intersect(.Tvars, names(data)),
  names_from = "Series",
  values_from = "Value",
  labels_from = if (any(names(data) == "Label")) "Label" else NULL,
  expand.date = FALSE,
  ...
)

Arguments

data

raw data from the API: A long format data frame where all values are stacked in a value column.

id_cols

character. Temporal identifiers of the data. By default all variables in .Tvars are selected.

names_from

character. The column containing the series codes. These will become the names of the new columns in the wider data format.

values_from

character. The column containing the data values.

labels_from

character. The column containing the labels describing the series.

expand.date

logical. TRUE will call expand_date on the data after reshaping.

...

further arguments passed to dcast or expand_date, no conflicts between these two.

Value

A data.table with the reshaped data.

See Also

wide2long, wide2excel, ugatsdb

Examples

1
2
# Return monthly macroeconomic indicators from the year 2000 onwards
long2wide(get_data("BOU_MMI", from = 2000, wide = FALSE))

ugatsdb documentation built on Nov. 26, 2021, 1:06 a.m.