For matching locationID records the assaociated locatioData is used to replace any existing value in columnName. NA values in locationID will be ignored.

table_updateColumn(
  locationTbl = NULL,
  columnName = NULL,
  locationID = NULL,
  locationData = NULL,
  verbose = TRUE
)

Arguments

locationTbl

Tibble of known locations.

columnName

Name to use for the new column.

locationID

Vector of locationID strings.

locationData

Vector of data to used at matching records.

verbose

Logical controlling the generation of progress messages.

Value

Updated tibble of known locations.

See also

Examples

library(MazamaLocationUtils) locationTbl <- get(data("wa_monitors_500")) wa <- get(data("wa_airfire_meta")) # We will merge some metadata from wa into locationTbl # Record indices for wa wa_indices <- seq(5,65,5) wa_sub <- wa[wa_indices,] locationID <- table_getLocationID( locationTbl, wa_sub$longitude, wa_sub$latitude, distanceThreshold = 500 ) locationData <- wa_sub$siteName locationTbl <- table_updateColumn(locationTbl, "siteName", locationID, locationData) # Look at the data we attempted to merge wa$siteName[wa_indices]
#> [1] "Twisp-Ewell St" "Cheeka Peak" #> [3] "Tacoma-Alexander Ave" "Auburn 29th St" #> [5] "Anacortes-202 Ave (SO-AQS)" "Quincy 3rd" #> [7] "Tulalip-Totem Beach Rd" "Shelton-W Franklin" #> [9] "Ellensburg-Ruby St" "Wenatchee-Fifth St" #> [11] "Walla Walla-12th St" "Chehalis-Market Blvd" #> [13] "Tacoma-S 36th St"
# And two columns from the updated locationTbl locationTbl_indices <- table_getRecordIndex(locationTbl, locationID) locationTbl[locationTbl_indices, c("city", "siteName")]
#> # A tibble: 13 × 2 #> city siteName #> <chr> <chr> #> 1 Okanogan County Twisp-Ewell St #> 2 NA NA #> 3 Tacoma Tacoma-Alexander Ave #> 4 Auburn Auburn 29th St #> 5 Anacortes Anacortes-202 Ave (SO-AQS) #> 6 Quincy Quincy 3rd #> 7 Tulalip Bay Tulalip-Totem Beach Rd #> 8 Shelton Shelton-W Franklin #> 9 Ellensburg Ellensburg-Ruby St #> 10 Wenatchee Wenatchee-Fifth St #> 11 Walla Walla Walla Walla-12th St #> 12 Chehalis Chehalis-Market Blvd #> 13 Tacoma Tacoma-S 36th St