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

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Tue Aug 30 21:20:14 CEST 2005


You can shorten the notation by=0 .


On Tue, 2005-08-30 at 09:30 -0400, roger bos wrote:
> Uwe,
>  Thanks. I have used merge a lot, but I didn't realize you could merge on 
> row names. I got it working now:
>  test <- merge(out.r[1:5, 1:3], out.p[1:5, 1:3], by="row.names", all.x=TRUE)
>  Thanks,
> Roger
> 
> 
>  On 8/30/05, Uwe Ligges <ligges at statistik.uni-dortmund.de> wrote: 
> > 
> > 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
> > 
> >
> 
> 	[[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