Find the value of x corresponding to the maximum or minimum of y
You have two numeric vectors, x and y, of the same length and want to find the value of x where y attains its maximum value
function with indexing.
> x <- seq(0, pi/2, .2) > y <- sin(2*x) > x[which.max(y)]  0.8
See rule 2.5 in The R Primer for more information.
Back to tips.