[R] comparing row by row in matrix

Petra Steiner steinep at uni-muenster.de
Tue Mar 26 23:18:24 CET 2002


Thank you, that is the solution.

And the RR-coeffizient (number of agreements/total number) is this:
(ma%*%t(ma)) / ncol(ma)

Regards, Petra


> I don't know the Russell-Rao coefficient but maybe this will help:
>
> You can compute the number of times y and x are both 1 (that's what your
> function f does) by counting 1s in y*x, i.e., sum(y*x), aka t(y)%*%x.
> Ordinary matrix multiplication does this row-by-column, so if M and N are
> two binary matrices, M%*%t(N) will have (i,j) entry equal to the count of
1s
> in common to row i of M and row j of N.
>
> Hope I've understood the problem correctly.
>
> Reid Huntsinger
>
> -----Original Message-----
> From: Petra Steiner [mailto:steinep at uni-muenster.de]
> Sent: Tuesday, March 26, 2002 2:08 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] comparing row by row in matrix
>
>
> Hello,
>
> and thanks for the two responses to my questions on binary matrixes, which
> showed me that the functions I needed do not exist.
>
> To get a distance matrix with the Russell-Rao-coefficient, I first have to
> compare each row of a binary matrix with each row and count how many
> elements are
> a. equal
> and
> b. 1.
>
> by
> f <- function(x,y) (sum(x == 1& y == x))
>
> Now how can I iterate this over a matrix without a loop? I think apply
etc.
> will not work in this case.
>
> Thanks for any help.
>
> Regards,
> Petra
>
> -
> ---------------------------------------------------
> Petra Steiner
> Arbeitsbereich Linguistik
> Universitaet Muenster
> Huefferstrasse 27
> 48149  Muenster
>
> Tel: 0251 / 83 39442
> petra at marley.uni-muenster.de
> http://santana.uni-muenster.de/~petra/
>
>
>
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.
> -.-
> r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._
>
>
> --------------------------------------------------------------------------
----
> Notice:  This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that
may be confidential, proprietary copyrighted and/or legally privileged, and
is intended solely for the use of the individual or entity named in this
message.  If you are not the intended recipient, and have received this
message in error, please immediately return this by e-mail and then delete
it.
>
>
============================================================================
==
>

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list