Hi,
I have two matrices with a common field = species what i want to do is make a matrix that combines the data held in the other two based on the species name. I.e ( simple example) Matrix 1 - monocot SPECIES V1 A 2 B 3 C 4 D 5 Matrix 2 - PCAresults SPECIES V2 A 0.2 B 0.3 C 4.1 D 3.2 matrix 3 - What i want SPECIES V1 V2 A 2 0.2 B 3 0.3 C 4 4.1 D 5 3.2 my attempt has been this test <-monocot[which(monocot$SPECIES%in%PCAresults$SPECIES),] But this returns matrix with only those found in each but doesn't "import" the data from PCAresults Any help would be greatly appreciated John ______________________________________________ [hidden email] 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. |
Hi all,
Sorry i forgot to mention there a species present in one matrix not in the other hence the problem i.e matrix 1 may have species E which isnt present in matrix 2 and matrix 2 may have species F not present in matrix 1. Sorry for the lack of clarification in the original post! John On 17 Dec 2010, at 15:19, John Haart wrote: Hi, I have two matrices with a common field = species what i want to do is make a matrix that combines the data held in the other two based on the species name. I.e ( simple example) Matrix 1 - monocot SPECIES V1 A 2 B 3 C 4 D 5 Matrix 2 - PCAresults SPECIES V2 A 0.2 B 0.3 C 4.1 D 3.2 matrix 3 - What i want SPECIES V1 V2 A 2 0.2 B 3 0.3 C 4 4.1 D 5 3.2 my attempt has been this test <-monocot[which(monocot$SPECIES%in%PCAresults$SPECIES),] But this returns matrix with only those found in each but doesn't "import" the data from PCAresults Any help would be greatly appreciated John ______________________________________________ [hidden email] 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. ______________________________________________ [hidden email] 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. |
In reply to this post by John Haart
Hi,
On Fri, Dec 17, 2010 at 10:19 AM, John Haart <[hidden email]> wrote: > Hi, > > I have two matrices with a common field = species what i want to do is make a matrix that combines the data held in the other two based on the species name. Look at the merge function: ?merge -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact ______________________________________________ [hidden email] 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. |
In reply to this post by John Haart
Hi John,
I'd recommend looking into ?merge. Jeremy Jeremy T. Hetzel Boston University
Jeremy T. Hetzel
Boston University |
In reply to this post by John Haart
Hi,
On Fri, Dec 17, 2010 at 10:22 AM, John Haart <[hidden email]> wrote: > Hi all, > > Sorry i forgot to mention there a species present in one matrix not in the other hence the problem i.e matrix 1 may have species E which isnt present in matrix 2 and matrix 2 may have species F not present in matrix 1. > > Sorry for the lack of clarification in the original post! This still isn't a problem, you can choose to include the results that appear in one data.frame vs. the other by playing with the all, all.x, all.y parameters in the merge function ... -steve > > John > On 17 Dec 2010, at 15:19, John Haart wrote: > > Hi, > > I have two matrices with a common field = species what i want to do is make a matrix that combines the data held in the other two based on the species name. > > I.e ( simple example) > > Matrix 1 - monocot > > SPECIES V1 > > A 2 > B 3 > C 4 > D 5 > > Matrix 2 - PCAresults > > SPECIES V2 > > A 0.2 > B 0.3 > C 4.1 > D 3.2 > > matrix 3 - What i want > > SPECIES V1 V2 > > A 2 0.2 > B 3 0.3 > C 4 4.1 > D 5 3.2 > > > > my attempt has been this > > test <-monocot[which(monocot$SPECIES%in%PCAresults$SPECIES),] > > But this returns matrix with only those found in each but doesn't "import" the data from PCAresults > > Any help would be greatly appreciated > > John > > ______________________________________________ > [hidden email] 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. > > ______________________________________________ > [hidden email] 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. > -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact ______________________________________________ [hidden email] 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. |
Free forum by Nabble | Edit this page |