[R] "pattern matching" accross multiple matrices

Martin Tomko martin.tomko at geo.uzh.ch
Thu Nov 8 18:30:42 CET 2007


Hi all,

I have a set of patterns which can occur in a series of (3) matrices. I 
want to identify those and create a fourth one with the identifiers of 
the cases.

Something like:

	for (i in 1:l) {
		for (j in 1:w) {
	
		A[A[i,j]==1 & D[i,j]==1 & P[i,j]==1] <- Case1;
		A[A[i,j]==-1 & D[i,j]==-1 & P[i,j]==-1] <- Case2;

etc....
}
}

the code seems to run, but is very slow.... Could anyone please suggest 
a better approach? I was thinking that 3 matrices could be stacked in a 
cube, and the column of a cube searched for a pattern, but am not sure 
how to do that...

Thanks
Martin



More information about the R-help mailing list