[R] R Equivalent to matlab's find() command?
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Thu Jun 8 14:59:36 CEST 2000
On Thu, 8 Jun 2000, Stephen Eglen wrote:
> hi,
>
> Just a very simple question: is there an R equivalent to the matlab
> command find(X) which returns the indices of vector X that store
> non-zero elements?
>
> e.g.
> > find( [1 0 0 1 0])
> ans =
>
> 1 4
>
> so, in R, how do I do:
>
> ans <- rfind( c(1,0,0,1,0))
>
> so that ans is the vector c(1,4)
rfind <- function(x) seq(along=x)[x != 0]
It's a peculiar name, though ....
--
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list