我shapefile从data.gov下载了县。我可以在传单中使用它们,如下所示来绘制 WA、ID 和 OR 中的县。我想让州边界更厚。我怎样才能做到这一点?
counties <- readOGR(paste0(dir, "/tl_2017_us_county.shp"),
layer = "tl_2017_us_county", GDAL1_integer64_policy = TRUE)
counties <- counties[counties@data$STATEFP %in% c("16", "41", "53"), ]
counties <- subset(counties, STATEFP %in% c("16", "41", "53") )
counties <- rmapshaper::ms_simplify(counties)
counties %>%
leaflet() %>%
setView(lng = -118.4942, lat = 47.2149, zoom = 5) %>%
addPolygons( fillColor = "green", fillOpacity = 0.5,
color = "black", opacity = 1.0, weight = .6, smoothFactor = 0.5,
highlightOptions = highlightOptions(color="white", weight=2, bringToFront = TRUE),
label= …Run Code Online (Sandbox Code Playgroud) 我有一个数据表,dt看起来像
location year value
NYC 2026 1
NYC 2026 2
NYC 2026 3
NYC 2026 4
NYC 2026 5
LA 2026 6
LA 2026 7
LA 2026 8
LA 2026 9
LA 2026 10
Run Code Online (Sandbox Code Playgroud)
我想对它们进行分组,city并year在value每组中的列中找到第二小的元素,所需的结果如下所示:
location year value
NYC 2026 2
LA 2026 7
Run Code Online (Sandbox Code Playgroud)
dt %>% grou_by(location, year) %>% nth(value, 2)
将无法正常工作。任何帮助表示赞赏。
上面的数据表可以通过以下方式创建:
dt <- structure(list(location = c("NYC", "NYC", "NYC","NYC", "NYC",
"LA", "LA", "LA", "LA", "LA"),
year = c(2026, 2026, 2026, 2026, …Run Code Online (Sandbox Code Playgroud) 我想从 dataframe 中找到kdataframe 中所有点的最近邻居。这怎么可行?它似乎只需要一组数据,并且只需要一个查询点。ABsklearn.neighbors.NearestNeighbors
喜欢:
samples = [[0., 0., 0.], [0., .5, 0.], [1., 1., .5]]
from sklearn.neighbors import NearestNeighbors
neigh = NearestNeighbors(n_neighbors=1)
neigh.fit(samples)
print(neigh.kneighbors([[1., 1., 1.]]))
Run Code Online (Sandbox Code Playgroud)
我想要一个包含多个查询点的数据框而不是 [[1., 1., 1.]]
PS我想要的指标是Mahalanobis其sklearn.neighbors.KDTree不接受,而且scipy.spatial.KDTree甚至没有任何指标的选择。