max and min are vectors. When you use a vector as a bound on a for loop, then only the first element in the vector is used.
Your for Max loop is overwriting Rhn in every iteration, so you might as well only use the last iteration.
Naming variables max or min is quite likely to lead to problems later when you try to use max() or min() as functions. At the very least it confuses readers of the code.