title: How to do hill climbing in R from a given starting point?
body: <p>I'm looking for a function that will do simple hill climbing on a vector, from a starting point that I provide. More formally: given a vector like <code>y &lt;- c(1,2,3,1,1)</code>, I want a function <code>hill(y, x0)</code> such that <code>hill(y, 1) == 3</code> (climbing from left gets to the top) and <code>hill(y, 5) == 5</code> (it moves left and right, but discovering it's on a plateau, just returns the starting value). I have trouble believing this doesn't exist, but haven't been able to find it so far. Anyone got a lead?</p>