am_pivot_longer {africamonitor} | R Documentation |
Reshape Column-Based Data to Long Format
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 (am_data(..., wide = FALSE)
).
It can also be used as a general purpose reshaping command - with an additional capability to handle variable labels.
Usage
am_pivot_longer(
data,
id_cols = intersect(c("ISO3", .AMT), names(data)),
to_value = setdiff(names(data), id_cols),
variable_name = "Series",
value_name = "Value",
label_name = "Label",
na.rm = TRUE,
variable.factor = TRUE,
label.factor = 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 |
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. |
variable.factor , label.factor |
logical. |
... |
further arguments passed to |
Value
A data.table
with the reshaped data.
See Also
Examples
# Return all indicators for Kenya and Nigeria from the year 2000 onwards
data <- am_data(c("KEN", "NGA"), from = 2000)
am_pivot_longer(data)