I have three dataframes of data. I would like to join or merge the dataframes so that they are all in the one dataframe based on Day (but not all columns have data for each day), but I also want to keep all of the other columns.
I have the prepared the following dummy data:
# Create three dataframes of dummy data
df = data.frame(matrix(rnorm(20), nrow=10))
df2 = data.frame(matrix(rnorm(15), nrow=5))
df3 = data.frame(matrix(rnorm(30), nrow=10))
Days = seq(1:10)
Days2 = seq(from =5, to=9)
df1_all <- data.frame(Days, df)
colnames(df1_all) <- c("Days", "Survey1", "Survey2")
df2_all <- data.frame(Days2, df2)
colnames(df2_all) <- c("Days", "Survey3", "Survey4", "Survey5")
df3_all <- data.frame(Days, df3)
colnames(df3_all) <- c("Days", "Survey6", "Survey7", "Survey8")
How would the three dataframes be combined so they have a common column of Days but all of the survey columns remain?
As you can see df1_all
and df3_all
have days that are 1
to 10
, but df2_all
has days that are 5
to 9
.