Milton Cezar Ribeiro
2006-Nov-03 14:25 UTC
[R] identify extremes positions of values into matrix
Um texto embutido e sem conjunto de caracteres especificado associado... Nome: n?o dispon?vel Url: stat.ethz.ch/pipermail/r-help/attachments/20061103/39e6883b/attachment.pl
Dimitris Rizopoulos
2006-Nov-03 14:34 UTC
[R] identify extremes positions of values into matrix
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: med.kuleuven.be/biostat 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 > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >Disclaimer: kuleuven.be/cwis/email_disclaimer.htm
Francisco J. Zagmutt
2006-Nov-03 18:48 UTC
[R] identify extremes positions of values into matrix
Oi Milton, Is this what you are after? x=read.table("miltondat.txt")>xV1 V2 V3 V4 V5 V6 V7 V8 V9 V10 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 1 1 1 0 0 3 0 0 0 0 0 1 1 1 0 0 4 0 0 0 0 0 0 0 0 0 0 5 0 0 2 2 2 0 0 0 0 0 6 0 0 0 2 2 2 0 0 0 0 7 0 0 2 2 2 2 2 2 0 0 8 0 0 0 0 0 0 0 0 0 0 idx=which(x==2,arr.ind=T) #Index of observations with values == 2 . Notice the use of arr.ind=t to get the rows and columns of the observations>idxrow col 5 5 3 7 7 3 5 5 4 6 6 4 7 7 4 5 5 5 6 6 5 7 7 5 6 6 6 7 7 6 7 7 7 7 7 8>range(idx[,"row"]) #gives you the min and max of the rows with x==2[1] 5 7>range(idx[,"col"])#gives you the min and max of the columns with x==2[1] 3 8 You can refine this and wrap it in a function to make reports in a more suitable form Regards Francisco Dr. Francisco J. Zagmutt College of Veterinary Medicine and Biomedical Sciences Colorado State University>From: Milton Cezar Ribeiro <milton_ruser at yahoo.com.br> >To: r-help at stat.math.ethz.ch >Subject: [R] identify extremes positions of values into matrix >Date: Fri, 3 Nov 2006 11:25:32 -0300 (ART) > >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 >stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code._________________________________________________________________ Try Search Survival Kits: Fix up your home and better handle your cash with Live Search!
Milton Cezar Ribeiro
2006-Nov-03 19:05 UTC
[R] identify extremes positions of values into matrix
Um texto embutido e sem conjunto de caracteres especificado associado... Nome: n?o dispon?vel Url: stat.ethz.ch/pipermail/r-help/attachments/20061103/1bde0ac8/attachment.pl