Performing loops on list of lists of rasters

此生再无相见时 提交于 2019-12-04 05:53:23

Does this work?

# Function to sample using a given number (returns list of three)
sample.number <- function(x) {
  rps <- lapply(rasters, function(y) randomPoints(raster(y),n=x))
  setNames(rps,paste0('sample',1:length(mv)))
}

# Apply sample.number() to your numberv list
sample.set <- lapply(numberv,sample.number)

# Function to extract values from a given sample
sample.extract <- function(x) {
  lapply(1:length(x),function(y) data.frame(x[[y]],extract(rasters[[y]],x[[y]])))
}

# Apply sample.extract() to the set of samples (returns list of four lists)
sample.values <- lapply(sample.set,sample.extract)

# Access sample 1 of number 200
summary(sample.values[[3]][[1]])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!