1

I am trying to convert latitude/longitude to Census Tract or FIPS using R studio. I am getting the following error message when I am running "system.time"

"Error in UseMethod("st_intersects") : no applicable method for 'st_intersects' applied to an object of class "data.frame" Timing stopped at: 0 0 0"

Entire Code:

library(sf)

list.files("./tl_2010_22_tract10")

census_tracts <- st_read("./tl_2010_22_tract10/tl_2010_22_tract10.shp")

head(census_tracts)


library(readxl)

DAT <- read_excel("~/DAT.xlsx")

View(DAT)

latlong_dat = data.frame(DAT)



latlong_sf <- latlong_dat 
filter(!is.na(LAT), !is.na(LONG)) 
st_as_sf(latlong_dat, coords = c("LONG", "LAT"), crs = 
st_crs(census_tracts))

head(latlong_dat)


system.time({intersected <- st_intersects(latlong_sf, census_tracts)})

Screenshot of code

DAT FILE

tospig
  • 7,762
  • 14
  • 40
  • 79
Sami
  • 11
  • 2
  • you need to assign your `st_as_sf()` call to an object. So you probaby should be doing `latlong_sf <- st_as_sf(latlong_dat, coords = c("LONG", "LAT"), crs = st_crs(census_tracts))` – tospig May 15 '22 at 09:00
  • It looks to me like you forgot to add pipes and/or assignments – AndS. May 15 '22 at 13:26

0 Answers0