[R] table and getting rownames

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Aug 17 14:39:48 CEST 2004


On Tue, 17 Aug 2004 merser at tiscali.dk wrote:

> say that i have this table
> >x<-table(adoc, oarb)
> >x
>                oarb
>                       0   1
> adoc
>     ab                1   0
>     am                5   1
>     ba               14   1
>     cc              271   3
>     ch               87   2
>     dz              362   6
>     fl                7   0
>     fs               84   2
> 
> is there an easy way to get the row names or row numbers of rows with
> oarb==0

That seems to be with *entry* zero, not oarb = 0?

> i.e. (ab, fl) or (1, 7)

rows(x)[x==0]
rownames(x)[rows(x)[x==0]]

will do what I think you meant to ask.

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list