Last active
June 8, 2016 21:51
-
-
Save nharrell04/1c60fcbf84dda4e8a6b278b792f0f39a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pollutantmean <- function(directory, pollutant, id) { | |
currentdir <- getwd() | |
if (currentdir != ~directory){ | |
setwd(~directory) ## returns Error in setwd(directory): cannot change working directory | |
} | |
monitorinfo <-read.csv(id)## takes id and reads that .CSV file | |
## will monitorinfo work if given a sequence e.g, 1:10? | |
pollutantcol <- monitorinfo[,pollutant] | |
pollutantcolnoNAs <- pollutantcol[!is.na(pollutantcol)] ## gets rid of NAs | |
meanpol <- mean(pollutantcolnoNAs) | |
meanpol | |
} | |
complete <- function(directory, id){ | |
currentdir <- getwd() | |
if (currentdir != ~directory){ | |
setwd(~directory) ## returns Error in setwd(directory): cannot change working directory | |
} | |
comdata <- data.frame(id,nobs) | |
for (i in id) { | |
indfile <- read.csv(id) | |
occurs <- length(indfile[,1])## gets the number of occurences ie rows from indfile | |
df_id_nobs <- data.frame(id,occurs) | |
merge(comdata,df_id_nobs) ## want to add a row to comdata w the label id and value occurs | |
comdata | |
} | |
} | |
corr <- function(directory, threshold = 0) { | |
currentdir <- getwd() | |
if (currentdir != ~directory){ | |
setwd(~directory) ## returns Error in setwd(directory): cannot change working directory | |
} | |
cor_vector <- c() | |
for (i in 332) ## 332 is the number of CSV files in the directory; better way to do this? | |
obs <- read.csv(i) | |
obs_noNas <- obs[!is.na(obs),1:3] ## want this to get rid of any row w/ a NA; obs should have 3 columms | |
if (length(obs_noNas[,1]) >= threshold) | |
{ | |
cor_sul_nit <- cor(obs_noNas[,2],obs_noNas[,3]) | |
cor_vector <- append(cor_vector,cor_sul_nit) | |
} | |
cor_vector | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment