警告消息:在mean.default(data_subset,na.rm = TRUE)中:参数不是数字或逻辑:返回NA

时间:2015-06-07 02:22:45

标签: r mean subset

以下代码返回错误,我不确定首先要查看什么。似乎问题在于均值函数,但是当我在控制台中运行相同的函数时,会返回结果。

   pollutantmean <- function(directory, pollutant, id = 1:332) {
  data_files_full <- list.files("directory", full.names = TRUE)
  tmp <- vector(mode = "list", length = length(data_files_full))

  for (i in seq_along(data_files_full)) {
  tmp[[i]] <- read.csv(data_files_full[[i]])
  output <- do.call(rbind, tmp)
  }
  data_subset <- output[id, "pollutant"]
  mean(data_subset, na.rm=TRUE)
}

我对此很新,任何建议都会受到赞赏。

0 个答案:

没有答案