Last active
July 11, 2017 11:37
-
-
Save ChristinaLK/37ecc5168c77ee93ad9a00704428121c to your computer and use it in GitHub Desktop.
Looping over spreadsheets to combine into a single dataframe
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
library(dplyr) | |
# create empty dataframe | |
df <- data.frame(Domain=character(), | |
Total=integer(), | |
Date=character()) | |
# loop thru data files + add to data frame | |
for (date in c('2012-2013','2014-2015','2016-2017')) { | |
# set data file path + read in data | |
data <- load_data(date=date, time=365) | |
# summarize pieces I need + add date identifier column | |
data_summary <- data %>% | |
select(Domain, CHTC_Total) %>% | |
group_by(Domain) %>% | |
summarize(Total = sum(CHTC_Total)) %>% | |
mutate(Date = date) | |
# add to master df | |
df <- rbind(df, data_summary) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment