以下代码返回错误,我不确定首先要查看什么。似乎问题在于均值函数,但是当我在控制台中运行相同的函数时,会返回结果。
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)
}
我对此很新,任何建议都会受到赞赏。