admin管理员组文章数量:1122832
Assume I have a spatial temporal dataframe which looks like:
# Load necessary libraries
library(sf)
library(dplyr)
# Create a simple spatial polygon grid
polygons <- st_make_grid(
st_bbox(c(xmin = 0, ymin = 0, xmax = 10, ymax = 10)),
cellsize = c(2, 2),
square = TRUE
) %>%
st_as_sf() %>%
mutate(poly_id = row_number()) # Add polygon identifiers
# Create a temporal variable with years
years <- seq(2000, 2005)
# Expand grid to simulate spatiotemporal data
spatiotemporal_data <- expand.grid(
poly_id = polygons$poly_id,
year = years
) %>%
left_join(polygons, by = "poly_id") %>%
st_as_sf()
# Add a variable with some NA values
set.seed(42) # For reproducibility
spatiotemporal_data <- spatiotemporal_data %>%
mutate(variable = ifelse(runif(n()) > 0.8, NA, rnorm(n())),
variable = if_else(poly_id == 3, NA, variable))
Now I would like first: do an temporal inter-/ extrapoliation within a poly_id. However I'm able to do run the temporal interpolarization by:
patiotemporal_data <- spatiotemporal_data %>%
arrange(poly_id, year) %>%
group_by(poly_id) %>%
mutate(across(variable, ~ ifelse(any(!is.na(.)), zoo::na.approx(., na.rm = TRUE, rule = 2),. ))) %>%
ungroup()
Now I want to fill the remaing NAs (in Group 3, as no variable was given) by spatial interpolariation.
Approaches I found yet, using e.g. point to interpolate on a grid. But what if I just want to fill the NAs? thanks.
本文标签: rspatial temporal interpolarizationStack Overflow
版权声明:本文标题:r - spatial temporal interpolarization - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303884a1932038.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论