I have files having the name with years. I listed all the files and taken the year value to a variable name. I want to create a column in the output file with all 365 days. But how can I give the variable name having the year value in the date sequence?
The name of the files is in the format 'E1901.txt', 'E1902.txt',.... Here is the script
setwd("location")
input_files = list.files(,pattern="[.]txt$")
total = data.frame()
for(i in 1:length(input_files)){
rf = read.csv(input_files[i])
year = regmatches(rf,regexec("E(.+).txt",rf))
year=sapply(year,"[",2)
print(year)
filenm = sub("txt","csv",rf)
date = seq(as.Date(paste(year,"/1/1")), as.Date(paste(year,"/12/31")), "day")
rf$date = date
rf= rf[,c(220,1:219)]
}
cat("\n Finished processing data of ",filenm)
total = do.call("rbind",rf)
write.csv(total, file="1901-2016.csv", row.names=FALSE, col.names=FALSE,sep =",")
Regards,