Hello Everyone,
I am relatively new to Rstudio. I have multiple CSV files and I want to combine them horizontally. The CSV files have two common columns (i.e. Date and Q ). I want to have an output csv for certain period of time using the Date columns as index. if the data is missing for any of dates from the CSV files then it should be filled "NA". See the figure below
I tried this script
library(readr)
#Create a dummy table for combining data
Date <- seq.Date(as.Date("2001-10-15"), as.Date("2001-10-20"), by = "day")
Date<-data.frame(Date)
colnames(Date)<-("Date")
data<-data.frame(matrix(NA,nrow=6,ncol=5))
x<-c("Flow (“Sno”,”Q”,”Volume(cf)”, “area(sf)”))
colnames(data)<-x
Table<-cbind(Date,data)
#import all csv files
list_of_files <- list.files(path = "C:/Users/ /Documents",
recursive = TRUE,
pattern = "\.csv$",
full.names = TRUE)
df <- readr::read_csv(list_of_files, id = "file_name")