Skip to content

Instantly share code, notes, and snippets.

@Radcliffe
Last active January 5, 2016 05:07
Show Gist options
  • Save Radcliffe/61a9d0aa1afd8744019e to your computer and use it in GitHub Desktop.
Save Radcliffe/61a9d0aa1afd8744019e to your computer and use it in GitHub Desktop.
Reshape expenditure data
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