gpt4 book ai didi

r - mutate 找不到函数

转载 作者:行者123 更新时间:2023-12-03 16:59:22 27 4
gpt4 key购买 nike

我正在通过这个网页处理 eBird 代码:
https://github.com/CornellLabofOrnithology/ebird-best-practices/blob/master/03_covariates.Rmd
除了使用我自己的数据。我有一个来自澳大利亚 gadm.org 的 .gpkg,以及我自己为澳大利亚选择的电子鸟数据。我完全遵循了代码,除了不使用“bcr”,因为我的数据集没有 bcr 代码,同时删除了 st_buffer(dist = 10000)来自 rgdal 代码,因为这使我由于某种原因无法实际下载 MODIS 数据。
编辑:我也使用了网站提供的数据,但仍然收到相同的错误
我被这个代码困住了:

lc_extract <- ebird_buff %>% 
mutate(pland = map2(year_lc, data, calculate_pland, lc = landcover)) %>%
select(pland) %>%
unnest(cols = pland)
它返回此错误:
Error: Problem with `mutate()` input `pland`.
x error in evaluating the argument 'x' in selecting a method for function 'exact_extract': invalid layer names
i Input `pland` is `map2(year_lc, data, calculate_pland, lc = landcover)`.)`
我似乎无法弄清楚如何纠正它,我对这样的密集地理空间代码很陌生。
链接里有免费的数据集,但是我还没试过,所以可能是我的数据与代码不兼容?但是,我查看了提供的 Gis-data.gpkg,我从 gadm 获得的数据似乎很好。
上面的前两个代码是:
neighborhood_radius <- 5 * ceiling(max(res(landcover))) / 2
ebird_buff <- red_knot %>%
distinct(year = format(observation_date, "%Y"),
locality_id, latitude, longitude) %>%
# for 2019 use 2018 landcover data
mutate(year_lc = if_else(as.integer(year) > max_lc_year,
as.character(max_lc_year), year),
year_lc = paste0("y", year_lc)) %>%
# convert to spatial features
st_as_sf(coords = c("longitude", "latitude"), crs = 4326) %>%
# transform to modis projection
st_transform(crs = projection(landcover)) %>%
# buffer to create neighborhood around each point
st_buffer(dist = neighborhood_radius) %>%
# nest by year
nest(data = c(year, locality_id, geometry))
calculate_pland <- function(yr, regions, lc) {
locs <- st_set_geometry(regions, NULL)
exact_extract(lc[[yr]], regions, progress = FALSE) %>%
map(~ count(., landcover = value)) %>%
tibble(locs, data = .) %>%
unnest(data)
}

最佳答案

网页的作者已经回答了这个问题。
解决方案是这样的代码:

lc_extract <- NULL
for (yr in names(landcover)) {
# get the buffered checklists for a given year
regions <- ebird_buff$data[[which(yr == ebird_buff$year_lc)]]
# get landcover values within each buffered checklist area
ee <- exact_extract(landcover[[yr]], regions, progress = FALSE)
# count the number of each landcover class for each checklist buffer
ee_count <- map(ee, ~ count(., landcover = value))
# attach the year and locality id back to the checklists
ee_summ <- tibble(st_drop_geometry(regions), data = ee_count) %>%
unnest(data)
# bind to results
lc_extract <- bind_rows(lc_extract, ee_summ)
}
学分转到:
马特·斯特里马斯-麦基

关于r - mutate 找不到函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63207709/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com