Skip to contents

add_capital_distance() allows you to add capital-to-capital distance to a (dyad-year, state-year) data frame. The distance variable that emerges (capdist) is calculated using the "Vincenty" method (i.e. "as the crow flies") and is expressed in kilometers.

Usage

add_capital_distance(data, transsum = "first")

add_cap_dist(...)

Arguments

data

a data frame with appropriate peacesciencer attributes

transsum

a character vector with one of the following acceptable inputs: "first" ("jan1") or "last" ("dec31"). Determines what to do for a yearly summary in the case of a capital transition. "first" ("jan1") selects the first capital coordinate observed in a given year while "last" ("dec31") selects the last capital coordinate observed in a given year. Default is "first" ("jan1"). See details section for more.

...

optional, only to make the shortcut (add_cap_dist()) work

Value

add_capital_distance() takes a (dyad-year, state-year) data frame and adds the capital-to-capital distance between the first state and the second state (in dyad-year data) or the minimum capital-to-capital distance for a given state in a given year.

Details

The function leans on attributes of the data that are provided by one of the "create" functions in this package (e.g. create_dyadyear() or create_stateyear()).

Be advised that "jan1" and "dec31" are alternate specifications for "first" and "last" respectively and exist as kind of a nudge for what you want to conceptualize the inputs for your year to be what is observed at its start or at its end. Obviously, there was no Jan. 1, 1954 or Dec. 31, 1875 for the Republic of Vietnam.

Author

Steven V. Miller

Examples


# \donttest{
# just call `library(tidyverse)` at the top of the your script
library(magrittr)
cow_ddy %>% add_capital_distance()
#> # A tibble: 2,214,930 × 4
#>    ccode1 ccode2  year capdist
#>     <dbl>  <dbl> <dbl>   <dbl>
#>  1      2     20  1920    735.
#>  2      2     20  1921    735.
#>  3      2     20  1922    735.
#>  4      2     20  1923    735.
#>  5      2     20  1924    735.
#>  6      2     20  1925    735.
#>  7      2     20  1926    735.
#>  8      2     20  1927    735.
#>  9      2     20  1928    735.
#> 10      2     20  1929    735.
#> # ℹ 2,214,920 more rows

create_stateyears() %>% add_capital_distance()
#> Joining with `by = join_by(ccode, year)`
#> # A tibble: 17,511 × 4
#>    ccode statenme                  year mincapdist
#>    <dbl> <chr>                    <dbl>      <dbl>
#>  1     2 United States of America  1816      5905.
#>  2     2 United States of America  1817      5905.
#>  3     2 United States of America  1818      5905.
#>  4     2 United States of America  1819      5905.
#>  5     2 United States of America  1820      5905.
#>  6     2 United States of America  1821      5905.
#>  7     2 United States of America  1822      5744.
#>  8     2 United States of America  1823      5744.
#>  9     2 United States of America  1824      5744.
#> 10     2 United States of America  1825      5744.
#> # ℹ 17,501 more rows
# }