
Please have a look at this :-)

> ar1 <- array(data=c(1:16),dim=c(4,4))
> ar2 <- array(data=c(1,2,3,3,5:16),dim=c(4,4))
> z<-ar1==ar2
> ar1
     [,1] [,2] [,3] [,4]
[1,]    1    5    9   13
[2,]    2    6   10   14
[3,]    3    7   11   15
[4,]    4    8   12   16
> ar2
     [,1] [,2] [,3] [,4]
[1,]    1    5    9   13
[2,]    2    6   10   14
[3,]    3    7   11   15
[4,]    3    8   12   16
> z
      [,1] [,2] [,3] [,4]
[1,]  TRUE TRUE TRUE TRUE
[2,]  TRUE TRUE TRUE TRUE
[3,]  TRUE TRUE TRUE TRUE
[4,] FALSE TRUE TRUE TRUE
> which(z==FALSE)
[1] 4
> 

HTH




Federico Abascal <fabascal@cnb.uam.es> 
Sent by: r-help-bounces@stat.math.ethz.ch
26-04-07 04:14 PM

To
r-help@stat.math.ethz.ch
cc

Subject
[R] comparing two matrices, row by row






Estimated people,

I have two matrices:

ar1 <- array(data=c(1:16),dim=c(4,4))
ar2 <- array(data=c(1,2,3,3,5:16),dim=c(4,4))

They only differ in the fourth row. I would like to compare them in
order to know which columns are equal.

The following works, but I would like to have a better solution, and not
to use what someone called "prehistorical loops":

for(i in c(1:4)) { cat(as.character(i),": ",
as.character(setequal(ar1[i,],ar2[i,])), "\n") }
1 :  TRUE
2 :  TRUE
3 :  TRUE
4 :  FALSE

I cannot devise how to use the apply function for this.
Thanks a lot,
Federico

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
Regístrate ya - http://correo.espanol.yahoo.com/

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



============================================================================================
DISCLAIMER AND CONFIDENTIALITY CAUTION:\ \ This message and ...{{dropped}}

