Skip to content

Instantly share code, notes, and snippets.

@ryan-hill
Last active October 17, 2016 19:18
Show Gist options
  • Save ryan-hill/3a12bc8182d7766ecb97e9427d3120b1 to your computer and use it in GitHub Desktop.
Save ryan-hill/3a12bc8182d7766ecb97e9427d3120b1 to your computer and use it in GitHub Desktop.
#Code loops through StreamCat files on drive and combines into long table
#Also removes ancillary columns
combine_streamcat = function(x, wd){
hydro.rgns <- c("01","02","03S","03N","03W","04","05","06","07","08","09","10L","10U","11","12","13","14","15","16","17","18")
for(i in 1:length(hydro.rgns)){
print(hydro.rgns[i])
if(i == 1){
outDF = read.csv(paste0(wd, x, '_Region', hydro.rgns[i], '.csv'))
}else{
tmpDF = read.csv(paste0(wd, x, '_Region', hydro.rgns[i], '.csv'))
outDF = rbind(outDF, tmpDF)
}
}
outDF = outDF[ , c(1, 6:length(outDF))]
return(outDF)
}
#Example of how to use
#wd, wd2, and wd3 are local directories
inputs = c('303d','305b','AgKfct','AgKfctRpBf100','CoalMines','Loss','LossRpBf100','Lossyr','LossyrRpBf100','Pesticides97', 'TMDLs', 'Vegdist', 'VegdistRpBf100', 'Wet550', 'WetIndx')
for(i in 1:length(inputs)){
print(inputs[i])
tmpDF = combine_streamcat(inputs[i], wd3)
template = merge(template, tmpDF, all.x=T, all.y=F)
}
write.csv(template, paste0(wd2, 'output_StreamCat2.csv'), row.names=F)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment