I have a list of data.frames in R. I want to join them together using join_all
but the variable they have in common does not have exactly the same name.
Here is an example dataset
compA <- rep(1:35)
compB <- rep(1:35)
compC <- rep(1:35)
valuesa <- rnorm(35)
valuesb <- rnorm(35)
valuesc <- rnorm(35)
A <- data.frame(compA, valuesa)
B <- data.frame(compB, valuesb)
C <- data.frame(compC, valuesc)
list <- list(A, B, C)
Here, CompA, CompB, and CompC are all identical, but the 'values' variables are all different. I want to rename all the variables in the list which contain "comp" to have the same name so I can merge all dataframes in the list into one dataframe by "Comp".
JointData <- join_all(list, by="Comp", type='left')
Does anyone know how to do this?
This question How to find common variables in a list of datasets & reshape them in R? seems to be the closest, but he's not actually renaming his variables as far as I can see.