[R] how to find the location of the first TRUE of a logical vector

Douglas Bates bates at stat.wisc.edu
Wed Mar 5 23:09:48 CET 2003


Jason Liao <jg_liao at yahoo.com> writes:

> without having to check the vector element by element? Thanks a lot!

If vec is your vector of logical values then

match(TRUE, vec)

should work.  It will return NA if there are no TRUE values.



More information about the R-help mailing list