View source: R/find_equivalents.R
| find_equivalent_codes | R Documentation |
Find which codes should be combined to reconstruct older or newer codes across multiple dates. Creates groups dynamically to fit the provided date range, with flexible labelling functionality.
find_equivalent_codes(
classification,
dates,
labels = TRUE,
graph = klass_graph(classification),
date_format = "%Y"
)
find_equivalents(
classification,
dates,
labels = TRUE,
graph = klass_graph(classification),
date_format = "%Y"
)
classification |
The Klass classification to be used |
dates |
The dates that equivalent sets of codes should be found for. |
labels |
This parameter controls whether or not to add group labels to groups of
equivalent sets. If "1508 Ålesund, 1580 Haram" If This parameter also accepts a named list of labelling functions. The resulting dataset will contain a label column for each of the supplied functions. The names of the label columns are specified using the names of the list of functions. The functions provided in this parameter can accept any of the following
parameters: The following list, when supplied to this parameter, creates two label
columns: one containing the codes and names ( list(
label1 = function(code, name, date, ...) {
label_codes <- date == max(date)
paste(code[label_codes], name[label_codes], collapse = ", ")
},
label2 = function(code, date, ...) {
label_codes <- date == max(date)
paste(code[label_codes], collapse = ", ")
}
)
|
graph |
Optional. Generating the graph using |
date_format |
Optional. Passed directly to format, this is used to
specify the output format for the |
This function provides a solution to the problem of split or
combined codes in Klass classifications. When using update_klass to ask
"what is this code in this version of the classification in this other
version of the classification?", the answer is sometimes that the code has
been split into two or more codes (or combined from two or more codes, if
trying to back-date a code), and therefore that the code cannot be updated.
The solution provided by find_equivalent_codes is answering the question: "in
these versions of the classification, which codes were equivalent to this
code in this other version of the classification?".
Consider the following example of two codes combining into one. Here, "a"
and "b" are valid at t1, and are combined into "c" at t2.
t1 t2 a ---| b ---+-> c
update_klass would inform us that "a" can be updated to
"c" at t2, unless we specified combine = FALSE, in which case the
result would be NA. find_equivalent_codes() would inform us that the
equivalent of the codes "a" and "b" in t1 at t2 is "c".
We can also consider a code splitting into two. In this example, "a" is
valid at t1, and splits into "b" and "c" at t2.
t1 t2 a |-----> b |-----> c
update_klass is unable to provide an updated code due to the
split, and would return NA. find_equivalent_codes would inform us that the
equivalent codes of "a" at t1 is "b" and "c" at t2.
find_equivalent_codes can handle more than two dates. In the following
example, "a" splits into "b" and "c" at t2, and "b" and "c"
combine into "d" at t3. find_equivalent_codes can inform us that "a" is
equivalent to "b" and "c" at t2, and "d" at t3.
t1 t2 t3 a |-----> b | |-----> c +-> d
find_equivalent_codes will only search in the time range we specify. As a
consequence, generating sets of equivalent codes over longer time spans
will generally create larger sets than using shorter time spans.
To illustrate this behavior, we can add a new code "e" to the previous
example, and have "d" and "e" combine into "f" at t4.
t1 t2 t3 t4 a |-----> b | |-----> c |-> d | e---------------+--> f
Finding the
equivalents of "a" in t1 at t2 and t3 returns the same sets as
before:
t1: "a"
t2: "b" and "c"
t3: "d"
However, if we also wanted to know the equivalent set for t4, the result would be:
t1: "a" and "e"
t2: "b", "c" and "e"
t3: "d" and "e"
t4: "f"
find_equivalents is a legacy alias for find_equivalent_codes.
A data.frame with columns:
date containing the input dates
code containing the set of equivalent codes in each date
name containing the names of each code
validFrom and validTo values for each code returned
By default, labels, giving a unique group label for each group of equivalent sets.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.