我将如何在列表中的多个二进制数据帧中找到0的组数?

问题描述 投票:0回答:1

我正在尝试在列表中的多个数据帧中输出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”

  1. stop(“列表没有\” x \“”)

  2. 。local(x,...)

    ] >>
  3. raster(onedf)

  4. raster(onedf)

  5. FUN(X [[i]],...)

  6. 1.lapply(df_list,function(onedf){

Rastermat

丛集

tot

有人可以帮我吗?我真的很固执该做什么。

我正在尝试在列表中的多个数据帧中输出0上的组数。我相信要执行此操作的程序包是raster R程序包。这是我的尝试... set.seed(12345)output_1 <...>

r list dataframe r-raster r-package
1个回答
0
投票

唯一的问题是您需要使用矩阵而不是data.frames。

© www.soinside.com 2019 - 2024. All rights reserved.