Description Usage Arguments Value Examples
Tidy the data and merges data accordingly to a time range and by the provinces concerned by a split/combined event and return a data frame for the time range imputed.
1 2 |
df |
A data frame containing at least the variables |
sel |
A vector of character to select only the variable to merge. By default, select all the variables. |
FUN |
A function to apply on the data when merging the province
together. By default, |
from |
Initial date of the time range selected for the province
definition, of the class |
to |
Final date of the time range selected for the province
definition, of the class |
diseases |
A vector of character used to know which history of Vietnam
has to be taken for the merging event as two diseases has different story.
Used if you want the same merging event as your infectious disease dataframe,
for more details look at the |
df2 |
A data frame containing at least the variables |
args |
string vector, column name of the additional arguments |
FUN2 |
A function to apply on df2 when merging the province together,
to keep the same information at every step of the merging process. By
default |
... |
additional arguments to pass to FUN and FUN2. |
A object of the same class as df
in which all the provinces
that needed to be merged (according to the time range) are merged.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # For all the following examples, we will use the data from the package gso.
library(gso) # for the "content"
library(magrittr) # for "%>%"
library(dplyr) # for "filter"
migration_rate <- gso::content %>% filter(data_name == "demography_12") %>%
.$data %>% .[[1]] %>%
mutate(year = as.numeric(year))
# if you want to have the data expressed by province, with the province's
# definition of 1992 in Vietnam:
merge_prov(migration_rate, from = "1992-01-01")
# If you want the province's definition between 1992 and 2010 in Vietnam:
merge_prov(migration_rate, from = 1992, to = 2010)
# You can change the function
merge_prov(migration_rate, from = "1992", FUN = mean)
# You can also use weighted mean by providing the weighted in another
# data frame
pop_size <- gso::content %>% filter(data_name == "demography_5") %>%
.$data %>% .[[1]] %>% dplyr::select(province, year, total) %>%
mutate(year = as.numeric(year))
merge_prov(migration_rate, from = "1992-01-01", FUN = weighted.mean,
df2 = pop_size, args = "total")
# You can define the merge_prov function only on certain columns
pop_info <- gso::content %>% filter(data_name == "demography_1") %>%
.$data %>% .[[1]] %>%
mutate(year = as.numeric(year))
merge_prov(pop_info, sel = "average_population_thous_pers",
from = 1992, FUN = weighted.mean,
df2 = pop_size, args = "total")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.