I have a data frame called biny which is an observation of about 9k rows geocoded values, 18 columns. I'm trying to loop through and find the next nearest value, with the items grouped by Precinct. the problem is that the mapping here seems to be sending the rows and columns to map2_dfr, instead of the respective latitude and longitude.
dplyr::group_by(PRECINCT) %>%
purrr::map2_dfr(.$long, .$lat,
~spatialrisk::points_in_circle(, .x, .y,
lon = long,
radius = 1000)[2,])
Error: Mapped vectors must have consistent lengths:
* `.x` has length 18
* `.y` has length 8409
I've tried so far running this as a data table, as a function, and about a dozen ways in between, and can't get this to run on any of them. not married to the group_by, just want to run that points_in_circle for each respective precinct.
Frustrating element, this works just fine:
ans1 <- purrr::map2_dfr(bind$long, bind$lat,
~spatialrisk::points_in_circle(bind, .x, .y,
lon = long,
radius = 1000)[2,])
I was simply trying to run that on each precinct, but it seems to dislike that option.