Compare and remove duplicates with min value of another column
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all! I have an excel file with 4 columns and many rows. I want to compare and remove duplicates of column 1 by keeping only the records with the respective maximum value in column 4.
Further explanation; I have duplicates in column 1 (num). If I choose one value from column 1 (num) and all its duplicate records, I want to keep only the record with maximum value in the respective column 4 (tfc) by comparison and remove all the other duplicate rows. I need to do this for all the records and finally get an output with unique values in columns 1 (num) with the respective other values of column 2 (tc) and 3 (id) and the max value in column 4 (tfc). I have attached a sample file herewith. Please help me with this.
0 commentaires
Réponses (1)
KSSV
le 21 Mai 2020
num = xlsread("sample.xlsx") ;
C1 = num(:,1) ; C4 = num(:,end) ;
[c,ia,ib] = unique(C1) ;
N = length(c) ;
iwant = zeros(N,4) ;
for i = 1:N
[val,idx] = max(C4(ib==1)) ;
t = num(ib==i,:) ;
iwant(i,:) = t(idx,:) ;
end
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!