Let's say I have the following data frame in R:
d <- read.table(text='Name Month Rate1 Rate2
Aira 1 12 23
Aira 2 18 73
Aira 3 19 45
Ben 1 53 19
Ben 2 22 87
Ben 3 19 45
Cat 1 22 87
Cat 2 67 43
Cat 3 45 32', header=TRUE)
I want to calculate the average of Rate2 for each quartile of Rate1. For example, what is the average of Rate2 for observations from the 0th to 25th percentile of Rate1, the 26th to 50th percentile of Rate1, and so on.
How can I do this?