[R] comparing two matrices, row by row

Federico Abascal fabascal at cnb.uam.es
Thu Apr 26 12:44:49 CEST 2007


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/



More information about the R-help mailing list