[R] seeking advice for manipulating matrices to find the difference

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Aug 30 15:22:32 CEST 2005


roger bos wrote:

> I have two matrices (see example below) and I want the differences for the 
> matching row numbers, but the row numbers are not identical in the two 
> matrices. There are probably many ways to do this. Anyone know of any easy 
> way to do this? I could loop over them, but you know what they say about for 
> loops... Thanks, Roger

For example merge() by row numbers and calculate the differences in the 
next step.

Uwe Ligges


>  > out.r[1:5, 1:3]
> 1 2 3
> 1100 -0.0992 -0.0802 -0.0653
> 1200 -0.1242 -0.0417 0.0082
> 1300 -0.1681 -0.0211 -0.0958
> 1400 -0.0985 -0.1217 0.0026
> 1500 -0.0318 -0.0437 -0.0302
> 
>>out.p[1:5, 1:3]
> 
> 1 2 3
> 1100 -0.0564 -0.0573 -0.0224
> 1200 0.0528 -0.1134 -0.1186
> 1400 -0.0144 -0.1079 NA
> 1500 0.0919 -0.0371 -0.1602
> 1600 NA NA NA
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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




More information about the R-help mailing list