Skip to content
Prev 305848 / 398502 Next

effective way to return only the first argument of "which()"

On Wed, Sep 19, 2012 at 3:20 PM, Mike Spam <ichmagspam at googlemail.com> wrote:
It's long felt a little hack-ish but you can actually use which.min()
or which.max() on logical vectors for just this purpose.

x <- sample(20)

which.max(x < 5) # first x satisfying the condition.

Cheers,
Michael