Dear all, I am looking for a way to identify the row and column names of all elements within a matrix which fulfill some specified condition. Example: I have a correlation matrix of the following form: Y1 Y2 X1 0.4 0.3 X2 0.6 0.1 Suppose, I want to know which elements are smaller than 0.2, so the desired output should be something like: "X2 Y2" Thank you, Florian Koller ______________________ GfK Fernsehforschung GmbH Research Consulting & Development Nordwestring 101 D-90319 N??rnberg Fon +49 (0)911 395-3554 Fax +49 (0)911 395-4130 www.gfk.de / www.gfk.com _________________________ Diese E-Mail (ggf. nebst Anhang) enth??lt vertrauliche und/oder rechtlich gesch??tzte Informationen. Wenn Sie nicht der richtige Adressat sind, oder diese E-Mail irrt??mlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet. This e-mail (and any attachment/s) contains confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
On 22-Nov-05 Florian.Koller at gfk.de wrote:> Dear all, > > I am looking for a way to identify the row and column names of all > elements > within a matrix which fulfill some specified condition. > > Example: I have a correlation matrix of the following form: > > Y1 Y2 > X1 0.4 0.3 > X2 0.6 0.1 > > Suppose, I want to know which elements are smaller than 0.2, so the > desired > output should be something like: > > "X2 Y2"The clue is the "arr.ind" parameter in 'which' (default=FALSE): > A [,1] [,2] [1,] 0.4 0.3 [2,] 0.6 0.1 > which(A<0.2, arr.ind=TRUE) row col [1,] 2 2 Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 22-Nov-05 Time: 12:03:45 ------------------------------ XFMail ------------------------------