[R] identify extremes positions of values into matrix

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Fri Nov 3 15:34:51 CET 2006


try this:

# `mat'  is your matrix
apply(which(mat == 2, arr.ind = TRUE), 2, range)


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Milton Cezar Ribeiro" <milton_ruser at yahoo.com.br>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, November 03, 2006 3:25 PM
Subject: [R] identify extremes positions of values into matrix


> Hi R-friends around world!
>  I have a matrix that looks like bellow one.
> Each cell are filled with values 0, 1 or 2.
> In fact I have a lot of 512x512 matrices, with
> values varying from 0 to 999.
>  I need to retrieve the left and right columns
> and the top and botton lines of the matrix
> where occours for example the value 2.
> Column and row labels are included at the example.
>
>    1234567890
> 1 0000000000
> 2 0000011100
> 3 0000011100
> 4 0000000000
> 5 0022200000
> 6 0002220000
> 7 0022222200
> 8 0000000000
>
>  At this example, the right answer are:
>  collumns 3 and 8
>  lines 5 and 7
>  Any idea of how can I solve this?
>  Kind regards,
>  Miltinho
>
>
> ---------------------------------
>
> Música para ver e ouvir: You're Beautiful, do James Blunt
> [[alternative HTML version deleted]]
>
>


--------------------------------------------------------------------------------


> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list