[R] find indices of nonzero elements

Ott Toomet siim at obs.ee
Tue Oct 9 09:30:56 CEST 2001


Hi,

use:

which( a>0, arr.ind=TRUE)

best wishes,

Ott



On Mon, 8 Oct 2001, David A Richmond wrote:

> Hi,
> 	Is there a function func(x) where x is an array such that it
> returns a list of the indices of all non-zero elements of the array?
>
> for example:
> a:
> 1 0 0
> 0 0 1
> 0 1 0
>
> func(a) returns two vectors r and c:
> r c
> 1 1
> 2 3
> 3 2
>
>
> daver

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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