-
Notifications
You must be signed in to change notification settings - Fork 0
/
complete.R
34 lines (30 loc) · 1.07 KB
/
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
27
28
29
30
31
32
33
34
#!/usr/bin/R
#
# Another program created from the 2nd project in R-programming
# On Coursera
#
# by: Francis Kessie
#
# complete.R is a function that reads a directory full of files and
# reports the number of completely observed cases in each data file.
# The function returns a data frame where the first column is the name
# of the file and the second column is the number of complete cases.
complete <- function(specdata, ids = 1:332){
directory <- specdata
id_list <- c()
complete_dataset <- c()
for (id in ids) {
id_list <- c(id_list, id)
csvFiles <- list.files(pattern="\\.csv")[id]
file_list <- vector('list', length=length(csvFiles))
df_list <- lapply(X=csvFiles, read.csv, header=TRUE)
names(df_list) <- csvFiles
df <- do.call("rbind", df_list)
good <- complete.cases(df)
complete_data <- nrow(df[good, ])
complete_dataset <- c(complete_dataset, complete_data)
}
dataframes <- data.frame(id = id_list, nobs = c(complete_dataset))
print(dataframes)
}
complete("specdata", 1)