I need to merge about 19000 dataframes in R by their dates, and then merge with one more dataframe afterwards. I need to have the data in separate columns to perform a loop that has regression modelling for each of the 19000 dataframes.
I tried using the merge command, but all of the dataframes share the same columns, "DATE" and "RET", and the merge command does not allow more than 3 duplicates because it is limited to only the name itself, the name with the .x at the end, and the name with the .y at the end. I want the columns to be numbered by the dataset that they come from. For example, I want there be "DATE" in the first column, and "RET1," "RET2," and "RET3," and so forth until 19000 or so. I've also tried figuring out how to rename all the columns by numbering them RET1, RET2, and so forth but I could not find a solution to that either.
This is the failure to rename the names by column:
for (j in 1:19938){
colnames(HPR_Split_New[[j]]) <- c("DATE",j)
}
This is the failure to merge all the databases together:
merged.data.frame = Reduce(function(...) merge(..., by=c('DATE'), all=T), HPR_Split_New)
For the renaming failure, I expected the column names to be renamed to RET1, RET2, etc, but the code actually did nothing at all..
For the merging failure, it said that there were too many duplicates and it couldn't merge anymore. Here is one of the errors:
47: In merge.data.frame(..., by = c("DATE"), all = T) :
column names ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’, ‘RET.x’, ‘RET.y’ are duplicated in the result"
Please help me. I've haven't use R before and I've been stuck on combining these dataframes for over a week.