I’m working in R with the following dataset for a metabolomics study.
first Name Area Sample Similarity
120 Pentanone 699468 PO4:1 954
120 Pentanone 153744 PO2:1 981
126 Methylamine 83528 PO4:1 887
126 Unknown 32741 PO2:1 645
126 Sulfurous 43634 PO1:1 800
I want to be able to selected in the first column, within the rowns with same value (for example 120), the compounds with same name (for example pentanone). From this selection I want to copy the row information that corresponds to the highest similarity and created new columns within the table. In this case the following information:
120 Pentanone 153744 PO2:1 981
I know that “send me the code posts” are not very appreciated by I would greatly appreciated some clues on how to start.
There are many options. You already have one example using
plyr; here are two more.Base R approach, using
aggregateandmerge:A
sqldfapproach: