[R] indexing a vector

Erin Hodgess hodgess at uhddx01.dt.uh.edu
Tue May 8 05:30:56 CEST 2001


Hi Jeff!

Try this:

which(mymatrix == 4, arr.ind=TRUE)

Hope this help!
Sincerely,
Erin M. Hodgess, Ph.D.
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
One Main Street 
Houston, TX 77002
e-mail: hodgess at uhddx01.dt.uh.edu


 



Subject: Re: [R] indexing a vector
	charset="iso-8859-1"
> > Dear R-List,
> >
> > How can one look up the row/column number for a given value in a matrix
or
> > data.frame?  For example in a matrix that contains only unique values
for
> > in [,1] how can I find value x in [,1] and report its row number?
> >
>
> match(x,matrix[,1])
>
> -thomas

    As a follow up to this question,  what's the easiest way to
    find the column and row indicies for a specified value in a matrix,
    when you don't know which column it's in (as assumed above)?

    So if   mymatrix <- matrix(c(3, 2, 4, 1), nrow = 2),  what's the easiet
way
    to see that the value 4 is in position (1, 2) ?

    Thanks much,

        Jeff Miller



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