# [R] Coercion/conversion of logical index to integer index

Prof Brian D Ripley ripley at stats.ox.ac.uk
Wed May 29 08:47:31 CEST 2002

```On Wed, 29 May 2002 holki659 at student.otago.ac.nz wrote:

>
> Hi all,
>
> This question has significant potential to be a stupid one, but as I could find no hints in
> the manual or previous posts:
>
> If you have a logical index X:
>
> >X
> [1] TRUE FALSE TRUE TRUE FALSE
>
> And you want an equivalent integer index Y:
>
> >Y
> [1] 1 3 4
>
> Is there no easy way?  (I'm thinking of the equivalent of FIND in Matlab)

seq(along=X)[X] is easy enough, and which(X) is even easier (to use, if
unnecessarily complex here).

--
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```