createMatchup: createMatchup()

Description Usage Arguments Examples

Description

Creates a closure of the matchup() function that stores with the matchup() function data for all of its arguments except for its first, the vector of elements that need to be matched. This allows one to create quick, 1:1 matching functions that can be reused, akin to Excel's VLOOKUP or INDEX/MATCH functionality.

Usage

1
createMatchup(matching_data, match_this, to_this)

Arguments

matching_data

a data frame containing columns matching two things, i.e. the column names you are inputting in the match_this and to_this arguments.

match_this

column name of what you want matched (ex. state initials)...

to_this

...column name of what you want the above matched to (ex. state names)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
Let's try using createMatchup to create a function that matches US state
initials to state names, like the example for the matchup() function.
Remember, this is how we matched state initials to names before:

\code{matchup(vector_of_state_initials, us_states, "state", "state_name")}

Now let's create a function to do this, called initials_to_names():

\code{initals_to_names <- createMatchup(us_states, "state", "state_name")}

Now, we just need to input the vector_of_state_initials that was the first
argument in the matchup() function above to produce its output when it comes
to matching state names to initials. This:

\code{initials_to_names(vector_of_state_initials)}

Produces the same output as this:

\code{matchup(vector_of_state_initials, us_states, "state", "state_name")}

jakesherman/jakemisc documentation built on May 18, 2019, 9:08 a.m.