Last active
January 2, 2017 16:25
-
-
Save mGalarnyk/f3242633441fec2171fa63195938ddaa to your computer and use it in GitHub Desktop.
complete.R This file is used for the John Hopkins Data Science Specialization (R Programming). This file is posted for the blog post reviewing the specialization https://medium.com/@GalarnykMichael/in-progress-review-course-2-r-programming-jhu-coursera-ad27086d8438#.ui3hb8n46
This file contains hidden or 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
complete <- function(directory, id = 1:332) { | |
# Format number with fixed width and then append .csv to number | |
fileNames <- paste0(directory, '/', formatC(id, width=3, flag="0"), ".csv" ) | |
# Reading in all files and making a large data.table | |
lst <- lapply(fileNames, data.table::fread) | |
dt <- rbindlist(lst) | |
return(dt[complete.cases(dt), .(nobs = .N), by = ID]) | |
} | |
#Example usage | |
complete(directory = '~/Desktop/specdata', id = 20:30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment