[R] R Equivalent to matlab's find() command?
Uwe Ligges
ligges at statistik.uni-dortmund.de
Thu Jun 8 15:27:51 CEST 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)
Sorry, first answer was wrong!
Try:
which(x!=0)
Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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