[R] Output of row and column names
(Ted Harding)
Ted.Harding at nessie.mcc.ac.uk
Tue Nov 22 13:03:47 CET 2005
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 ------------------------------
More information about the R-help
mailing list