sm_pivot_longer {samadb} | 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 (sm_data(..., wide = FALSE)
).
Internally it uses melt
from data.table.
Usage
sm_pivot_longer(
data,
id_cols = intersect(.SAMADB_T, 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 electricity indicators from the year 2000 onwards
data <- sm_data("ELECTRICITY", from = 2000)
sm_pivot_longer(data)