Felix Wave
2007-May-04 11:26 UTC
[R] Get the difference between two matrices with different length
Hello, I have got two matrices with different length. The matrices have 3 columuns. The first two are coordinates. The third is a measurement. Now I want to get a subtraction between every single value of the third column (between matrix1 and matrix2), but only if the two first coordinates in matrix1 and matrix2 are the same. I tried "FUN=?" in aggregate and ave, but I don't know the command for such a subtraction? Thank's a lot. Felix --------------- The matrixes (examlple): 1 0.1 0.0042 1 0.2 0.00423 1 0.4 0.00467 1 0.5 0.00518 1 0.6 0.0061 1 0.1 0.0043 1 0.2 0.00442 1 0.3 0.00433 1 0.4 0.0045 1 0.5 0.00524 1 0.7 0.006 My aim: ------- 1 0.1 -0.0001 1 0.2 -0.00019 1 0.4 0.00017 1 0.5 -0.00006
Dimitris Rizopoulos
2007-May-04 11:52 UTC
[R] Get the difference between two matrices with different length
try this:
ind1 <- do.call("paste", c(as.data.frame(mat1[, 1:2]), sep =
"\r"))
ind2 <- do.call("paste", c(as.data.frame(mat2[, 1:2]), sep =
"\r"))
mat1[ind1 %in% ind2, 3] - mat2[ind2 %in% ind1, 3]
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Felix Wave" <felix-wave at vr-web.de>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, May 04, 2007 1:26 PM
Subject: [R] Get the difference between two matrices with different
length
> Hello,
> I have got two matrices with different length. The matrices have 3
> columuns. The first two are coordinates. The third is a measurement.
>
> Now I want to get a subtraction between every single value of the
> third column (between matrix1 and matrix2), but only if the two
> first coordinates in matrix1 and matrix2 are the same.
>
> I tried "FUN=?" in aggregate and ave, but I don't know the
command
> for such a subtraction?
>
>
> Thank's a lot.
> Felix
>
>
> ---------------
>
> The matrixes (examlple):
>
> 1 0.1 0.0042
> 1 0.2 0.00423
> 1 0.4 0.00467
> 1 0.5 0.00518
> 1 0.6 0.0061
>
>
> 1 0.1 0.0043
> 1 0.2 0.00442
> 1 0.3 0.00433
> 1 0.4 0.0045
> 1 0.5 0.00524
> 1 0.7 0.006
>
>
>
> My aim:
> -------
> 1 0.1 -0.0001
> 1 0.2 -0.00019
> 1 0.4 0.00017
> 1 0.5 -0.00006
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Philippe Grosjean
2007-May-04 12:04 UTC
[R] Get the difference between two matrices with different length
Hello, The answer is in one page of the R Wiki (just created to address such a question, by the way): http://wiki.r-project.org/rwiki/doku.php?id=tips:data-manip:calc_on_two_tables ..............................................<?}))><........ ) ) ) ) ) ( ( ( ( ( Prof. Philippe Grosjean ) ) ) ) ) ( ( ( ( ( Numerical Ecology of Aquatic Systems ) ) ) ) ) Mons-Hainaut University, Belgium ( ( ( ( ( .............................................................. Felix Wave wrote:> Hello, > I have got two matrices with different length. The matrices have 3 > columuns. The first two are coordinates. The third is a measurement. > > Now I want to get a subtraction between every single value of the > third column (between matrix1 and matrix2), but only if the two > first coordinates in matrix1 and matrix2 are the same. > > I tried "FUN=?" in aggregate and ave, but I don't know the command > for such a subtraction? > > > Thank's a lot. > Felix > > > --------------- > > The matrixes (examlple): > > 1 0.1 0.0042 > 1 0.2 0.00423 > 1 0.4 0.00467 > 1 0.5 0.00518 > 1 0.6 0.0061 > > > 1 0.1 0.0043 > 1 0.2 0.00442 > 1 0.3 0.00433 > 1 0.4 0.0045 > 1 0.5 0.00524 > 1 0.7 0.006 > > > > My aim: > ------- > 1 0.1 -0.0001 > 1 0.2 -0.00019 > 1 0.4 0.00017 > 1 0.5 -0.00006 > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >
Reasonably Related Threads
- How to select rows with identical index from two matrix?
- Reg : using two different matrix : how to do t.test
- Problem with lsa package (data.frame) on Windows XP
- Read data from .csv file as a matrix and compare the different between two matrix
- matrix() Help