Get distinct row based on row number or value
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Furqan Hashim
am 11 Okt. 2020
Bearbeitet: Ameer Hamza
am 11 Okt. 2020
I have a table which contains products, owner and prices and products are not distinct as an example generate a dummy table using:
Upload = table();
Upload.Name = ['A'; 'B'; 'C'; 'C'];
Upload.Owner = ['D'; 'E'; 'F'; 'G'];
Upload.Price = [10; 20; 40; 30];
From the above table how can I get distinct rows based on row number. I want to get the 2nd row in case where there is a duplication the output would be:
Upload = table();
Upload.Name = ['A'; 'B'; 'C'];
Upload.Owner = ['D'; 'E'; 'G'];
Upload.Price = [10; 20; 30];
How can I achieve distinct row based on price value, where the choosen row would be the one where price is highest. The output would be:
Upload = table();
Upload.Name = ['A'; 'B'; 'C'];
Upload.Owner = ['D'; 'E'; 'F'];
Upload.Price = [10; 20; 40];
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 11 Okt. 2020
Bearbeitet: Ameer Hamza
am 11 Okt. 2020
Try this
Upload = table();
Upload.Name = ['A'; 'B'; 'C'; 'C'];
Upload.Owner = ['D'; 'E'; 'F'; 'G'];
Upload.Price = [10; 20; 40; 30];
[~, ia] = unique(Upload.Name(end:-1:1));
New_Upload1 = Upload(end-ia+1, :);
[~, idx] = splitapply(@(x) max(x), Upload.Price, findgroups(Upload.Name));
New_Upload2 = Upload(cumsum(idx), :);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!