Skip to content

Commit

Permalink
Assignmet 1
Browse files Browse the repository at this point in the history
  • Loading branch information
waytoocool committed Feb 4, 2018
0 parents commit f1359dc
Show file tree
Hide file tree
Showing 335 changed files with 772,461 additions and 0 deletions.
14 changes: 14 additions & 0 deletions part1/complete.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
complete <- function(directory, id = 1:332){
obs <- c()
for (x in id){
a <- file.path(directory, formatC(x, width = 3, flag = "0"))
b <- paste(a, "csv", sep = ".")
data <- read.csv(b)
# a <- data[!is.na(data[,2]) & !is.na(data[,3]),]
a <- sum(complete.cases(data))
# obs <- c(obs, length(a[[1]]))
obs <- c(obs, a)
}
df = data.frame(id, obs)
df
}
14 changes: 14 additions & 0 deletions part1/corr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
corr <- function(directory, threshold = 0) {
matrix <- c()
for (x in 1:332){
a <- file.path(directory, formatC(x, width = 3, flag = "0"))
b <- paste(a, "csv", sep = ".")
data <- read.csv(b)
len <- sum(complete.cases(data))
if (len > threshold){
c <- cor(data[complete.cases(data), "sulfate"], data[complete.cases(data), "nitrate"])
matrix <- c(matrix, c)
}
}
matrix
}
14 changes: 14 additions & 0 deletions part1/mean.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pollutantmean <- function(directory, pollutant, id = 1:332){
Sum = 0
length = 0
for (x in id){
a <- file.path(directory, formatC(x, width = 3, flag = "0"))
b <- paste(a, "csv", sep = ".")
data <- read.csv(b)
Sum = Sum + sum(data[[pollutant]], na.rm = TRUE)
length = length + length(data[[pollutant]][!is.na(data[[pollutant]])])
}
mean = Sum/length
mean

}
Loading

0 comments on commit f1359dc

Please sign in to comment.