I'd like to join multiple data frames by Date that have identical column names, and the same dimensions, but the values may be different. The joined data frame should be the mean between each value for each matching column.
My problem is similar to these questions, and the answers given provide similar solutions to what I need, however, they do not fully answer my question. The Python code (2.) is the closest to what I need, but I can't code in Python well enough:
- Combining Multiple Identically-Named Columns in R
- inner merge dataFrame with identical column names and apply aggregate function
I would prefer a solution using dplyr and/or purrr. But I am always willing to learn more about base R.
The input data looks like this:
df1 <- data.frame(Date=c("2019-01-01","2019-01-02","2019-01-03"),A=c(3,2,1),B=c(2,2,2),C=c(1,3,3))
df2 <- data.frame(Date=c("2019-01-01","2019-01-02","2019-01-03"),A=c(1,2,3),B=c(4,4,4),C=c(3,3,1))
df3 <- data.frame(Date=c("2019-01-01","2019-01-02","2019-01-03"),A=c(5,2,3),B=c(4,5,4),C=c(3,3,1))
The output that I would want is:
df4 <- data.frame(Date=c("2019-01-01","2019-01-02","2019-01-03"),A=c(3,2,2.3),B=c(3.3,3.6,3.3),C=c(2.3,2.3,1.6))
Thanks for the help.