Below is the script to generate a reproducible dataframe:
id <- c(1:20)
a <- as.numeric(round(runif(20,-40,40),2))
b <- as.numeric(round(a*1.4+60,2))
df <- as.data.frame(cbind(id, a, b))
i would like to calculate the mean of "b" under different condition for "a". for example, what is the mean of "b" when -40 =< a < 0; and what is the mean of "b" when 0=< a <=40.
Thank you very much!