I need to find the minimum and the maximum values of a vector, but the minimum one needs to be positioned inside before the maximum one. So, given the vector:
v <- c (8,2,1,3,5,7,4)
the minimum value would be '1' (the 3rd element) and the maximum '7' (the sixth element). The maximum value would not be indeed '8' (the 1th element) because it occurs before the minimum '1' (the 3rd element).
I looked at the functions 'min' and 'max' (and their faster versions pmin and pmax), but apparently they are only able to find the highest minimum and maximum values, with no restrictions in place. The same for the range function.
Is there anyone that could help?
You can do:
range(v[which.min(v):length(v)])
[1] 1 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With