我提供了以下代码:
set.seed(123)
mat <- matrix(sample(c(0,1), 225, prob=c(0.8,0.2), replace=TRUE), nrow = 15)
set.seed(1234)
mat2 <- matrix(sample(c(0,1), 225, prob=c(0.8,0.2), replace=TRUE), nrow = 15)
set.seed(99)
mat3 <- matrix(sample(c(0,1), 225, prob=c(0.8,0.2), replace=TRUE), nrow = 15)
list <- list(mat, mat2, mat3)
library(igraph)
library(raster)
lapply(list, function (list) {
Rastermat <- raster(list)
Clumps <- as.matrix(clump(Rmat, directions = 8))
#turning the clumps into a list
tot <- max(Clumps, na.rm=TRUE)
res <- vector("list", tot)
for (i in 1:tot){
res[i] <- list(which(Clumps == i, arr.ind = TRUE))
}
})
我的行Rastermat <- raster(list)
引发错误:
。local(x,...)中的错误:列表中没有“ x”。
我将如何在列表上执行光栅。帮助将不胜感激。
。local(x,...)中的错误:列表中没有“ x”。
上述错误是因为raster
功能需要x
,它仅是以下受支持格式的文件名:
filename (character), Extent, Raster*, sf, SpatialPixels*, SpatialGrid*, object, 'image', matrix, im, or missing. Supported file types are the 'native' raster package format and those that can be read via rgdal
。
基本上,您要传递的对象应该是spatial
对象上的某种对象。
如果您的列表包含空间对象,请传递并尝试。