Removing rows duplicates based on some conditions
Afficher commentaires plus anciens
Hello. I already asked a very similar question here, but I didn't understand the commands well, so I decided to ask for help again. I now have a file with 7 columns. I need to exclude the lines where the values in the third column are the same, but based on the conditions: the date (column 1), the time (column2) and the index (column3) cannot be repeated together and you must keep only the line where the value of the seventh column is the largest. The matrix looks like this:
20140101 2100 1762 -5.983 -37.483 26.8 11000
20140101 2100 1762 -5.983 -37.483 36.8 15000
20140109 2040 1762 -5.983 -37.483 25.0 3000
20140109 2040 1762 -5.983 -37.483 28.0 7000
20140130 2250 1762 -5.983 -37.483 22.0 3000
20140109 2040 1763 -5.992 -37.483 25.0 4000
20140109 2040 1763 -5.992 -37.483 23.2 6000
20140114 1940 1763 -5.992 -37.483 34.0 6000
And I want this result:
20140101 2100 1762 -5.983 -37.483 36.8 15000
20140109 2040 1762 -5.983 -37.483 28.0 7000
20140130 2250 1762 -5.983 -37.483 22.0 3000
20140109 2040 1763 -5.992 -37.483 23.2 6000
20140114 1940 1763 -5.992 -37.483 34.0 6000
In other words, the conditions are: if you have more than one row with the same date (for example, 2040101) in column 1, the same time (for example, 2100) in column 2 and the same index (for example, 1762 ) in the third column, keep only the row where the value in the last column is greater. In the case of the example I gave, just keep:
20140101 2100 1762 -5.983 -37.483 36.8 15000
20140109 2040 1762 -5.983 -37.483 28.0 7000
20140130 2250 1762 -5.983 -37.483 22.0 3000
20140109 2040 1763 -5.992 -37.483 23.2 6000
20140114 1940 1763 -5.992 -37.483 34.0 6000
Thank you so much for your help!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!