[R] logical comparison of two matrices
Federico Calboli
f.calboli at ucl.ac.uk
Sat Jan 24 19:47:24 CET 2004
Dear All,
how can I get a logical comparison between matrices (or vectors) in a if
statement?
Whenever I try I get the following:
> S<-rbind(c(.25,0,0),c(0,.2,0),c(0,0,.1))
> P<-rbind(c(.75,.15,.01),c(.2,.8,.09),c(.05,.05,.9))
>
>
> aa<-function(S,P){
+ if (S == P){
+ return("OK")
+ }
+ else {
+ return("No match")
+ }
+ }
>
>
> aa(S,P)
[1] "No match"
Warning message:
the condition has length > 1 and only the first element will be used in:
if (S == P) {
The warning clearly states that only the first element was used, and
this would not be good enough.
If comparing the whole matrices is not possible I could be happy just
comparing the two diagonals.
regards,
Federico Calboli
--
=================================
Federico C. F. Calboli
PLEASE NOTE NEW ADDRESS
Dipartimento di Biologia
Via Selmi 3
40126 Bologna
Italy
tel (+39) 051 209 4187
fax (+39) 051 251 208
f.calboli at ucl.ac.uk
More information about the R-help
mailing list