[R] Index of item in matrix

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Apr 3 16:24:48 CEST 2003


white.denis at epamail.epa.gov writes:

> Try these:
> 
> which.col <- function (mat, x) (which(mat==x)-1) %/% nrow(mat) + 1
> which.row <- function (mat, x) (which(mat==x)-1) %% nrow(mat) + 1
> 
> Knowing the R community, there may be already functions to do this.

There is. Take another look at ?which.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907



More information about the R-help mailing list