If x is your matrix
> F F F F
> T F F F
> F F F T
Try:
cbind(col(x)[which(x)],row(x)[which(x)])
giving
[,1] [,2]
[1,] 1 2
[2,] 4 4
doc. dr. Andrej Blejec
National Institute of Biology
Vecna pot 111 POB 141
SI-1000 Ljubljana
SLOVENIA
Tel: + 386 1 423-33-88
Fax: + 386 1 423-50-38
E-mail: andrej.blejec@uni-lj.si
andrej.blejec@nib.si
> -----Original Message-----
> From: John Sorkin [mailto:jsorkin@grecc.umaryland.edu]
> Sent: Tuesday, October 14, 2003 7:41 PM
> To: s-news@lists.biostat.wustl.edu
> Subject: [S] code for finding row and column number of cells
> with T in a n by n logical matrix
>
>
> I have an square NxN matrix of logical values (i.e. T or F).
> I would like a suggestion for some code to determine the row
> and column number of the matrix cells that are T. For example
> for the 4x4 matrix
>
> F F F F
> T F F F
> F F F T
>
> the code would return 2,1
> and 4,4
>
> I am running S-Plus 6.1 on windows 2k.
>
> Thanks
> John
>
>
>
> John Sorkin MD, PhD
> Chief, Biostatistics and Informatics
> Baltimore VA Medical Center GRECC and
> University of Maryland School of Medicine Claude Pepper OAIC
> 410-605-7119
> john@grecc.umaryland.edu
> Confidentiality Notice: This email message, including any
> attachments, is for the sole use of the intended recipient(s)
> and may contain confidential and privileged information. Any
> unauthorized use, disclosure or distribution is prohibited.
> If you are not the intended recipient, please contact the
> sender by replying to this e-mail and destroy all copies of
> the original message. Baltimore Geriatrics Research,
> Education and Clinical Center
>
> --------------------------------------------------------------------
> This message was distributed by
> s-news@lists.biostat.wustl.edu. To unsubscribe send e-mail
> to s-news-request@lists.biostat.wustl.edu with the BODY of
> the message: unsubscribe s-news
>
|