I currently have a vector containing a list of paths leading to files such as:
files <- c("C:/Users/Me/Desktop/cc/canada/2016/Ontario.BRU",
"C:/Users/Me/Desktop/cc/canada/2017/Ontario.BRU",
"C:/Users/Me/Desktop/cc/canada/2018/Ottawa.BRU",
"C:/Users/Me/Desktop/cc/canada/2018/Ontario.BRU")
I would like to combine files that are ending by the same city into the same dataframe, one after another. If there is only one occurrence of a city, I would still save the dataframe as a csv file at the end. Here is the code I just started:
cad<-NULL
for(b in 1:length(files)){
country<-sub(".*/ *(.*?) */[[:digit:]].*", "\\1", files[b])
if(country=="canada"){
cad<-c(cad, files[b])
}
cad_cities <- unique((sub(".*/ *(.*?) *.BRU.*", "\\1", cad)))
for(c in 1:length(cad_cities)){
city<-sub(".*/ *(.*?) *.BRU.*", "\\1", cad)
}
}
I am stuck after this part. Thank you.
Edit: example of datafiles
2018,1,0,9999,-20.70,-23.00,-22.10,81.00,0.00,000,-991,-991,-991,-2.41,-991,-991,8.90,353,97.36,-991,-991,19.00,-991
2018,1,100,9999,-21.40,-22.70,-22.00,80.00,0.00,100,-991,-991,-991,-2.42,-991,-991,7.80,264,97.36,-991,-991,18.00,-991
2018,1,200,9999,-21.40,-22.50,-21.90,79.00,0.00,200,-991,-991,-991,-2.42,-991,-991,10.30,270,97.34,-991,-991,19.00,-991
2018,1,300,9999,-20.80,-21.90,-21.40,78.00,0.00,300,-991,-991,-991,-2.43,-991,-991,10.70,263,97.32,-991,-991,18.00,-991