I have hundreds of .csv files that are structured like this:
xyz25012013 <- data.frame(province = c("AB", "BC", "ON"), high = c(30, 20, 25), low = c(5, 2, 3))
xyz13122014 <- data.frame(province = c("AB", "BC", "ON"), high = c(20, 34, 25), low = c(1, 8, 3))
xyz30042014 <- data.frame(province = c("AB", "BC", "ON"), high = c(50, 21, 27), low = c(1, 9, 26))
xyz04072015 <- data.frame(province = c("AB", "BC", "ON"), high = c(26, 07, 90), low = c(4, 7, 3))
I want to import and merge/row bind all of them and retain the metadata date contained in the filename.
as.Date(substr(<filename>,4,11) format = "%d%m%Y")
I want the final output to look sort of like this:
date <- c(rep("25012013", 3), rep("13122014", 3), rep("30042014", 3), rep("04072015", 3))
xyz <- rbind(xyz25012013, xyz13122014, xyz30042014, xyz04072015)
xyz <- cbind(xyz, date)
xyz$date <- as.Date(xyz$date, format = "%d%m%Y")
print(xyz)