我正在尝试在列表中的多个数据帧中输出0上的组数。我相信要执行此操作的程序包是raster R程序包。这是我的尝试...
set.seed(12345)
output_1 <- matrix(sample(c(0,1), 225, prob=c(0.8,0.2), replace=TRUE), nrow = 15)
df_output_1 <- data.frame(output_1)
set.seed(99999)
output_2 <- matrix(sample(c(0,1), 225, prob=c(0.8,0.2), replace=TRUE), nrow = 15)
df_output_2 <- data.frame(output_2)
output_list <- list(df_output_2, df_output_2)
install.packages("raster")
library(raster)
lapply(output_list, function (onedf) {
Rastermat <- raster(onedf)
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
})
但是出现以下错误:
。local(x,...)中的错误:列表中没有“ x”
stop(“列表没有\” x \“”)
。local(x,...)
] >>raster(onedf)
raster(onedf)
FUN(X [[i]],...)
1.lapply(df_list,function(onedf){
Rastermat
丛集
tot
有人可以帮我吗?我真的很固执该做什么。
我正在尝试在列表中的多个数据帧中输出0上的组数。我相信要执行此操作的程序包是raster R程序包。这是我的尝试... set.seed(12345)output_1 <...>
唯一的问题是您需要使用矩阵而不是data.frames。