[6376] in s-news-athena

home help back first fref pref prev next nref lref last post

Re: Indices corresponding to a condition

daemon@ATHENA.MIT.EDU (Martin Maechler)
Fri Feb 3 10:16:21 1995

From: Martin Maechler <maechler@stat.math.ethz.ch>
Date: Fri, 3 Feb 1995 11:29:58 +0100
To: wand@agsm.unsw.edu.au
Cc: s-news@utstat.toronto.edu
In-Reply-To: <9502030620.AA16211@magic> (wand@agsm.unsw.edu.au)
Reply-To: Martin Maechler <maechler@stat.math.ethz.ch>

>>>>> "wand" == wand  <wand@agsm.unsw.edu.au> writes:

    wand> How does one find the indices of the entries of an array that
    wand> satisfy a certain condition?

    wand> For example, suppose
    wand> a <- c(0.34,0.56,0.12,0.67,0.98,0.41)

    wand> and you want the indices of those entries of "a" that are between
    wand> 0.2 and 0.8;

    wand> i.e. you want to obtain the array with entries
    wand> 1 2 4 6

    wand> Is there an easy way to do this?

Yes,

 ## A useful function :
 which <- function(logi) seq(logi)[logi]

 which( .2 < a  &  a < .8 )

or directly

 seq(a)[.2 < a  &  a < .8]


Martin Maechler <maechler@stat.math.ethz.ch>		 <><	 _
Seminar fuer Statistik, SOL F5				       _| |_
ETH (Federal Inst. Technology)	8092 Zurich	 SWITZERLAND  |_   _|
phone: x-41-1-632-3408		fax: ...-1086			|_|

home help back first fref pref prev next nref lref last post