Skip to contents

Split a table of addresses based on presence of coordinates

Usage

splitAddresses(addressTable)

Arguments

addressTable

(data.frame) A table of addresses. If there are not two columns named "LATITUDE" and "LONGITUDE", this function will just return this table as-is.

Value

(list) Two dataframes (geocoded and ungeocoded) inside of a list object. If there are not a LATITUDE and a LONGITUDE column, the original table of addresses is returned as the only item in the list.

Examples


addressTable <- tibble::tibble(
  "LOCATION_ID" = 1:6,
  "ADDRESS" = c(
    "456 WOOD STREET  MALDEN MA 02148",                  
    "123 MAIN ST APT 111  BROOKLINE MA 02446",        
    "999 DUCK STREET WEYMOUTH MA 02188",
    "100 PRESIDENT STREET MILTON MA 02186",                
    "1 SOUTH AVE REVERE MA 02151",             
    "99 BEACH ROAD SOUTH DENNIS MA 02660"),
  "LATITUDE" = c(NA_real_, 22.2, NA_real_, NA_real_, 43.666, 75.6),
  "LONGITUDE" = c(33.3, NA_real_, NA_real_, NA_real_, 43.666, 75.6)
    )
    
results <- splitAddresses(addressTable)

results$ungeocoded # addresses and location_ids without prepopulated coordinates
#> # A tibble: 4 × 4
#>   LOCATION_ID ADDRESS                                 LATITUDE LONGITUDE
#>         <int> <chr>                                      <dbl>     <dbl>
#> 1           1 456 WOOD STREET  MALDEN MA 02148            NA        33.3
#> 2           2 123 MAIN ST APT 111  BROOKLINE MA 02446     22.2      NA  
#> 3           3 999 DUCK STREET WEYMOUTH MA 02188           NA        NA  
#> 4           4 100 PRESIDENT STREET MILTON MA 02186        NA        NA  
results$geocoded # addresses and location_ids with prepopulated coordinates
#> # A tibble: 2 × 4
#>   LOCATION_ID ADDRESS                             LATITUDE LONGITUDE
#>         <int> <chr>                                  <dbl>     <dbl>
#> 1           5 1 SOUTH AVE REVERE MA 02151             43.7      43.7
#> 2           6 99 BEACH ROAD SOUTH DENNIS MA 02660     75.6      75.6