Last active
January 5, 2016 05:07
-
-
Save Radcliffe/61a9d0aa1afd8744019e to your computer and use it in GitHub Desktop.
Reshape expenditure data
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
library(dplyr) | |
d <- read.csv('expenditures.csv') | |
cats <- unique(d$ProgramCategory) | |
newnames <- gsub("[- ]", "", cats) | |
e <- d %>% | |
filter(ProgramCategory == cats[1]) %>% | |
select(Year:StudentsServed) | |
for (i in 1:13) { | |
e[[i+7]] <- d$DollarsPerADMServed[d$ProgramCategory == cats[i]] | |
} | |
for (i in 1:13) { | |
e[[i+20]] <- d$PercentOfTotal[d$ProgramCategory == cats[i]] | |
} | |
setnames(e, 8:20, paste0(newnames, 'DollarsPerADMServed')) | |
setnames(e, 21:33, paste0(newnames, 'PercentOfTotal')) | |
write.csv(e, 'expenditures-wide.csv', row.names=F) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment