R/stack-data.R
stack_data.Rd
This is a convenience function serving as an
intermediate step in preparing the data for visualization.
It is a basic wrapper for dplyr::bind_rows
that works
with the data preparation flow of flyover
. The input list
must be named to correctly identify the data sets after stacking.
stack_data(data_list, drop_mismatches = FALSE, group_var = "flyover_id_")
A named list of tabular data elements that
inherit from data.frame
.
This is generally the output of enlist_data
.
Logical. Whether to drop columns across data sets if they fail to appear in any one data set in the list.
Character string. After stacking, the resulting
data will have a new column with this name. The values
of this column are the names of data_list
.
These are used to identify the source of data and to
group variables for plotting in downstream functions.
A single tibble
with a new column having the name
passed to group_var
.
x <- list(old = data.frame(a = 1:3),
new = data.frame(a = 4:6, b = 7:9))
stack_data(x)
#> # A tibble: 6 × 3
#> flyover_id_ a b
#> <chr> <int> <int>
#> 1 old 1 NA
#> 2 old 2 NA
#> 3 old 3 NA
#> 4 new 4 7
#> 5 new 5 8
#> 6 new 6 9
stack_data(x, drop_mismatches = TRUE)
#> # A tibble: 6 × 2
#> flyover_id_ a
#> <chr> <int>
#> 1 old 1
#> 2 old 2
#> 3 old 3
#> 4 new 4
#> 5 new 5
#> 6 new 6