I'm hoping someone can help me with this problem. Let's say I have to data frames like the ones below.
A B C D
1 1 1 10 100
2 2 1 30 200
3 1 2 30 200
4 2 2 10 400
A B C D
1 1 1 10 300
2 2 1 20 400
3 1 2 30 300
4 2 2 20 600
My desired result is creating a combined frame with average values in columns C and D given a complete combined match of values in columns A and B, yielding a frame that looks like this:
A B C D
1 1 1 10 200
2 2 1 25 300
3 1 2 30 250
4 2 2 15 500
Anyone know a snippet of code that will help me in this pinch?
One base R
option could be:
aggregate(cbind(C, D) ~ ., FUN = mean, data = rbind(df1, df2))
A B C D
1 1 1 10 200
2 2 1 25 300
3 1 2 30 250
4 2 2 15 500
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With