Skip to content

Instantly share code, notes, and snippets.

View clanfear's full-sized avatar

Charles C. Lanfear clanfear

View GitHub Profile
@clanfear
clanfear / gist:e160ba2ddf5e90c7bc70dbd2cfb0dd94
Created August 15, 2019 18:44
Using sf and tidyverse to get weighted mean of neighbors for all columns
library(tidyverse)
library(sf)
st_queen <- function(a, b = a){
st_relate(a, b, pattern = "F***T****")
}
new_data <- original_data %>%
mutate(neighbors = st_queen(.)) %>%
st_drop_geometry() %>%