I am using the function below but I got wrong and the same answers to the when I call do functions. Could you please assist? What do I do wrong ?
pollutantmean <- function(directory, pollutant, id){
directory<- list.files("specdata", full.names = TRUE)
id <- 1:332
getmean <- data.frame(check.rows = TRUE)
for(i in seq_along(id)) {
getmean<- rbind(getmean,read.csv(directory[i], blank.lines.skip = TRUE))}
pollutant <- c("sulfate", "nitrate")
for (i in seq_along(pollutant)) { poll <- i}
mean(getmean[ , poll], na.rm = TRUE)
}
Then I call
pollutantmean("specdata", "nitrate", 23)
I got
# [1] 3.189369
when I call pollutantmean("specdata", "sulfate", 23)
, I got the same answer