-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solution
- Loading branch information
Rajesh Subramanian
committed
Sep 13, 2014
1 parent
920e225
commit fa1319a
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
programming-with-r/assignments/assignment-1-air-pollution/complete.R
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
complete <- function(directory, id = 1:332) { | ||
## 'directory' is a character vector of length 1 indicating | ||
## the location of the CSV files | ||
|
||
## 'id' is an integer vector indicating the monitor ID numbers | ||
## to be used | ||
|
||
## Return a data frame of the form: | ||
## id nobs | ||
## 1 117 | ||
## 2 1041 | ||
## ... | ||
## where 'id' is the monitor ID number and 'nobs' is the | ||
## number of complete cases | ||
allFiles <- list.files(path = directory, full.names = TRUE) | ||
selectedData <- data.frame() | ||
completeCases <- data.frame() | ||
nobs <- data.frame(); | ||
for (i in id) { | ||
selectedData <- (read.csv(allFiles[i],header=TRUE)) | ||
nobs <- sum(complete.cases(selectedData)) | ||
completeCases <- rbind(completeCases, data.frame(i,nobs)) | ||
} | ||
completeCases | ||
} |