# How to categorize a continuous variable based on its correlation with another continuous variable?

Two continuous variables are correlated but not in linear relation. How can I categorize the Independent variable to make two or more groups based on the correlation. For example age is correlated with depression. How can I split age in a way to find the highest depressed age group. I tried this using R and iris dataset, but looping take time and don't give me what I really want.

attach(iris)
cor(Sepal.Length,Sepal.Width)

a<-integer()
for (i in Sepal.Width){
b<-cor(Sepal.Length[Sepal.Width>i],Sepal.Width[Sepal.Width>i])
a<-c(a,b)
}
sort(a)