Skip to contents

Identify US State that each site is in (given ST, lat/lon, or FIPS)

Usage

state_from_sitetable(sites, ignorelatlon = FALSE)

Arguments

sites

data.frame or data.table, with one row per site, and column(s) that are either "ST" (2-letter abbreviation of State), "lat" and "lon", or "fips" or "bgfips" and optionally a column like "ejam_uniq_id" or "n"

ignorelatlon

set to TRUE to skip the slowest step of inferring ST from latlon in case you want to do that via sites2blocks info on blocks nearby

Value

the input table as a data.frame, but with these new columns if ST was not already a column: ejam_uniq_id, ST, statename, FIPS.ST, REGION, n

Examples

  state_from_sitetable(testpoints_10)
#>         lat        lon sitenumber        sitename ejam_uniq_id ST
#> 1  37.64122 -122.41065          1  Example Site 1            1 CA
#> 2  43.92249  -72.66370          2  Example Site 2            2 VT
#> 3  40.69351  -73.98002          3  Example Site 3            3 NY
#> 4  45.29520  -92.98184          4  Example Site 4            4 MN
#> 5  39.43730  -74.72370          5  Example Site 5            5 NJ
#> 6  45.67487  -94.81534          6  Example Site 6            6 MN
#> 7  33.14865 -117.19895          7  Example Site 7            7 CA
#> 8  34.01176  -80.95414          8  Example Site 8            8 SC
#> 9  43.01026  -89.45952          9  Example Site 9            9 WI
#> 10 40.74625  -74.25955         10 Example Site 10           10 NJ
#>         statename FIPS.ST REGION  n
#> 1      California      06      9  1
#> 2         Vermont      50      1  2
#> 3        New York      36      2  3
#> 4       Minnesota      27      5  4
#> 5      New Jersey      34      2  5
#> 6       Minnesota      27      5  6
#> 7      California      06      9  7
#> 8  South Carolina      45      4  8
#> 9       Wisconsin      55      5  9
#> 10     New Jersey      34      2 10
  state_from_sitetable(testoutput_ejamit_10pts_1miles$results_bysite[, .(ejam_uniq_id, ST, pop)])
#>    ejam_uniq_id ST      pop
#> 1             1 CA  14025.6
#> 2             2 VT   1584.6
#> 3             3 NY 137834.8
#> 4             4 MN   1906.0
#> 5             5 NJ   1519.5
#> 6             6 MN   3620.3
#> 7             7 CA  14810.4
#> 8             8 SC   3935.3
#> 9             9 WI   4183.8
#> 10           10 NJ  28896.7
  state_from_sitetable(testoutput_ejamit_10pts_1miles$results_bysite[, .(ST, pop)])
#>    ST      pop ejam_uniq_id
#> 1  CA  14025.6            1
#> 2  VT   1584.6            2
#> 3  NY 137834.8            3
#> 4  MN   1906.0            4
#> 5  NJ   1519.5            5
#> 6  MN   3620.3            6
#> 7  CA  14810.4            7
#> 8  SC   3935.3            8
#> 9  WI   4183.8            9
#> 10 NJ  28896.7           10
  state_from_sitetable(testoutput_ejamit_10pts_1miles$results_bysite[, .(ST, lat, lon, pop)])
#>    ST      lat        lon      pop ejam_uniq_id
#> 1  CA 37.64122 -122.41065  14025.6            1
#> 2  VT 43.92249  -72.66370   1584.6            2
#> 3  NY 40.69351  -73.98002 137834.8            3
#> 4  MN 45.29520  -92.98184   1906.0            4
#> 5  NJ 39.43730  -74.72370   1519.5            5
#> 6  MN 45.67487  -94.81534   3620.3            6
#> 7  CA 33.14865 -117.19895  14810.4            7
#> 8  SC 34.01176  -80.95414   3935.3            8
#> 9  WI 43.01026  -89.45952   4183.8            9
#> 10 NJ 40.74625  -74.25955  28896.7           10