Guest User

Untitled

a guest
Jun 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. pollutantmean <- function(directory = "specdata", pollutant = "sulfate", id =
  2. "001") {
  3. pollutantcount <- 0
  4. pollutantsum <- 0
  5.  
  6. filetype <- ".csv"
  7. pathswitch <- "."
  8.  
  9.  
  10. file_len <- nchar(id)
  11. if (file_len == 1) {
  12. new_id <- paste("00", id, filetype, sep = "")}
  13. else if (file_len == 2) {
  14. new_id <- paste("0", id, filetype, sep = "")}
  15. else
  16. new_id <- paste(id, filetype, sep = "")
  17. new_path <- file.path(pathswitch,directory, new_id)
  18. new_data <- read.csv(new_path)
  19. pollutantsum <- pollutantsum + sum(new_data[,pollutant], na.rm=TRUE)
  20. pollutantcount <- pollutantcount + length(na.exclude(new_data[,pollutant]))
  21. meanofpollutant <- (pollutantsum / pollutantcount)
  22. print(meanofpollutant)
Add Comment
Please, Sign In to add comment