在R Studio中使用均值函数时遇到问题。
下面是我的代码。
# Pollutant mean
pollutantmean <- function(directory, pollutant, id = 1:332)
{
sum_nitrate = 0
sum_sulphate = 0
print(directory)
print(pollutant)
print(id)
file.names <- dir(directory, pattern=".csv")
for ( i in id)
{
infile <- paste(directory, "/", file.names[i], sep="")
print(infile)
df1 <- read.csv(infile, header = TRUE)
sum_nitrate = sum_nitrate + mean(df1$nitrate, trim=0.1, na.rm=TRUE)
}
}
我在使用时遇到问题,请帮帮我。