I really just need another set of eyes on this code. As you can see, I am searching for files with the pattern "*45Fall...". But every time I run it, it pulls up the files "*45Sum..." and one time pulled up the "*45Win..." files. It seems totally random and the code clearly asks for Fall. I'm confused.
What I am doing is importing all files with "Fall_2040301", (there are many other numbers associated with "Fall" as well as many other names associated with "*Fall_2040301", as well as Win, Spr, and Sum). I am truncating them at 56 lines by removing the last 84 lines, and binding them together so that I can write them out as a group.
fnames <- dir("~/Desktop/RprojPuddle/modified_files", pattern = "*45Fall_2040301.csv")
read_data <- function(z){
dat <- fread(z, skip = 0, select = 1:3, )
return(dat[1:(nrow(dat)-84),])
}
datalist <- lapply(fnames, read_data)
bigdata <- rbindlist(datalist, use.names = T)
datalist = do.call("rbind", bigdata)
datalist
splitByHUCs <- split(bigdata, f = bigdata$HUC8 , sep = "\n", lex.order = TRUE)
saveFun_WRITE <- function(splitByHUCs, name_i) {
fwrite(splitByHUCs, file = paste0("~/Desktop/RprojPuddle/splitByHUCs/b02040301/splFall/", name_i, ".csv")) # save the file to the computer
}
mapply(FUN = saveFun_WRITE, splitByHUCs, name_i = names(splitByHUCs), SIMPLIFY = FALSE)
I used the same code used for the other seasons and it worked well. I know that it's Frankenstein code and I would welcome suggestions for tightening it up also, but really, it's working. Except for Fall. Thanks.