View source: R/hmatch_manual.R
hmatch_manual | R Documentation |
Match a data.frame with raw, potentially messy hierarchical data (e.g. province, county, township) against a reference dataset, using a dictionary of manually-specified matches.
hmatch_manual(
raw,
ref,
man,
pattern,
pattern_ref = pattern,
by,
by_ref = by,
code_col,
type = "left",
ref_prefix = "ref_",
std_fn = string_std,
...
)
raw |
data frame containing hierarchical columns with raw data |
ref |
data frame containing hierarchical columns with reference data |
man |
|
pattern |
regex pattern to match the hierarchical columns in |
pattern_ref |
regex pattern to match the hierarchical columns in |
by |
vector giving the names of the hierarchical columns in |
by_ref |
vector giving the names of the hierarchical columns in |
code_col |
name of the code column containing codes for matching |
type |
type of join ("left", "inner", or "anti"). Defaults to "left".
See join_types. Note that this function does not allow 'resolve
joins', unlike most other |
ref_prefix |
prefix to add to names of returned columns from |
std_fn |
function to standardize strings during matching. Defaults to
|
... |
additional arguments passed to |
a data frame obtained by matching the hierarchical columns in raw
and ref
based on sets of matches specified in man
, using the join type
specified by argument type
(see join_types for more details)
data(ne_raw)
data(ne_ref)
# create df mapping sets of raw hierarchical values to codes within ref
ne_man <- data.frame(
adm0 = NA_character_,
adm1 = NA_character_,
adm2 = "Bergen, N.J.",
hcode = "211",
stringsAsFactors = FALSE
)
# find manual matches
hmatch_manual(ne_raw, ne_ref, ne_man, code_col = "hcode", type = "inner")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.