I am trying to compare two data frames (df1, df2) of same structure (same dimensions, column names, row names, etc) and keep the maximum values between the two data frames. I actually have hundreds of columns and rows, but here is some pretend data:
df1:
Date Fruit Num Color
2013-11-24 Banana 2 Yellow
2013-11-24 Orange 8 Orange
2013-11-24 Apple 7 Green
2013-11-24 Celery 10 Green
df2:
Date Fruit Num Color
2013-11-24 Banana 22 Yellow
2013-11-24 Orange 8 Orange
2013-11-24 Apple 7 Green
2013-11-24 Celery 1 Green
There are many examples on SO doing similar things but in python not R: Comparing two dataframes and getting the differences, Compare two dataframes to get comparison value in in another dataframe etc.
I tried a dplyr approach but I don't know how to do this correctly for all the columns (hundreds).
library(dplyr)
test <- rbind(df1, df2)
test2 <- test %>%
group_by(Date) %>%
summarise(max = max(.))
Given my pretend data above, the desired output should be:
new.df:
Date Fruit Num Color
2013-11-24 Banana 22 Yellow
2013-11-24 Orange 8 Orange
2013-11-24 Apple 7 Green
2013-11-24 Celery 10 Green
Thanks for the help.