roger bos
2005-Aug-30 13:02 UTC
[R] seeking advice for manipulating matrices to find the difference
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 > 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]]
Uwe Ligges
2005-Aug-30 13:22 UTC
[R] seeking advice for manipulating matrices to find the difference
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, RogerFor 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
Reasonably Related Threads
- Initial values of the parameters of a garch-Model
- Help with predict.Arima with external regressor values [Repalced]
- Help with predict.Arima with external regressor values
- R badly lags matlab on performance?
- [LLVMdev] [llvm-testresults] bwilson__llvm-gcc_PROD__i386 nightly tester results