Я включил свою попытку:
set.seed(12345)
x <- matrix(sample(c(0,1), 225, prob=c(0.8,0.2), replace=TRUE), nrow = 15)
set.seed(9999)
y <- matrix(sample(c(0,1), 225, prob=c(0.8,0.2), replace=TRUE), nrow = 15)
set.seed(12345)
z <- matrix(sample(c(0,1), 225, prob=c(0.8,0.2), replace=TRUE), nrow = 15)
mat_list <- list(x, y, z)
library(igraph)
library(raster)
lapply(list, function (list) {
Rastermat <- raster(list)
Clumps <- as.matrix(clump(Rastermat, 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))
}
})
Но когда я запускаю это, я получаю вывод NULL для каждой матрицы в списке. Может кто-нибудь помочь мне разобраться в чем дело?
Отредактировано:
lapply(mat_list, function (onemat) {
Rastermat <- raster(onemat)
Clumps <- as.matrix(clump(Rastermat, 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))
}
res
})