-
Notifications
You must be signed in to change notification settings - Fork 1
/
complete.R
26 lines (22 loc) · 851 Bytes
/
complete.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
# Give us the file name for a given ID
specFileName <- function(id) {
paste(directory, "//", sprintf("%03d", id), ".csv", sep="")
}
# Read each file specified by ID
filesAsDataFrames <- lapply(lapply(id, specFileName), read.csv)
completeCount <- function(df) sum(complete.cases(df))
complete <- sapply(filesAsDataFrames, completeCount)
data.frame(id=id, nobs=complete)
}