wide2long: Reshape Column-Based Data to Long Format

Description Usage Arguments Value See Also Examples

View source: R/accessdb.R

Description

This function automatically reshapes wide (column-based) data into a long format akin to the format of the raw data coming from the database (get_data(..., wide = FALSE)).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
wide2long(
  data,
  id_cols = intersect(.Tvars, names(data)),
  to_value = setdiff(names(data), id_cols),
  variable_name = "Series",
  value_name = "Value",
  label_name = "Label",
  na.rm = TRUE,
  ...
)

Arguments

data

a wide format data frame where all series have their own column.

id_cols

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

to_value

character. The names of all series to be stacked into the long format data frame.

variable_name

character. The name of the variable to store the names of the series.

value_name

character. The name of the variable to store the data values.

label_name

character. The name of the variable to store the series labels.

na.rm

logical. TRUE will remove all missing values from the long data frame.

...

further arguments passed to melt.

Value

A data.table with the reshaped data.

See Also

long2wide, ugatsdb

Examples

1
2
3
# Return monthly macroeconomic indicators from the year 2000 onwards
data <- get_data("BOU_MMI", from = 2000)
wide2long(data)

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