Delete elements less than the last largest elementDeleting multiple elements from a listChanging the...

Is there a method for differentiating informative comments from commented out code?

Interpretation of non-significant results as "trends"

Moving millions of files to a different directory with specfic name patterns

What does "spinning upon the shoals" mean?

Curly braces adjustment in tikz?

What is the relationship between external and internal composition in a cartesian closed category?

Test Driven Development Roman Numerals php

Four ships at the ocean with the same distance

run bash scripts in folder all at the same time

Can Jimmy hang on his rope?

What exactly is a "murder hobo"?

Compute Manhattan distance from origin given a set of left-right-step directions

Blocks from @ jafe

What was the nature of the known bugs in the Space Shuttle software?

How many Jimmys can fit?

What do you call a situation where you have choices but no good choice?

As a supervisor, what feedback would you expect from a PhD who quits?

How do I talk to my wife about unrealistic expectations?

Sense of humor in your sci-fi stories

Why am I getting unevenly-spread results when using $RANDOM?

QR codes, do people use them?

Can one block with a protection from color creature?

Why does Trump want a citizenship question on the census?

Gory anime with pink haired girl escaping an asylum



Delete elements less than the last largest element


Deleting multiple elements from a listChanging the precision of data in a list of matricesJoin nested lists based on first and last elements within each listUsing Select function to select elements based on last element of nested listDelete only when there are two (or more) 1smaking two columns from 1D-horizontal dataDelete some elements based on the keysHow to set a particular element of a list to a number?delete an element list recursivelyElegant way of partitioning in two starting from the second element?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3












$begingroup$


Here is my list. The first column contains its index and second column has data.



list={{1, 170.93}, {2, 170.4}, {3, 174.08}, {4, 160.65}, {5, 166.44}, {6, 
169.75}, {7, 175.86}, {8, 177.6}, {9, 180.27}, {10, 182.82}, {11,
182.02}, {12, 186.65}, {13, 184.53}, {14, 186.17}, {15,
177.29}, {16, 172.06}, {17, 175.58}, {18, 168.09}, {19,
172.33}, {20, 165.1}, {21, 154.88}, {22, 161.28}, {23, 165.25}, {24,
165.15}, {25, 171.03}, {26, 174.55}, {27, 182.57}, {28,
191.02}, {29, 191.11}, {30, 184.93}, {31, 188.85}, {32, 191.44}};


I want to delete all numbers that are smaller than the last largest element. For example, I want to delete 4th, 5th and 6th elements because they are smaller than the last largest element (3rd). Similarly, I want to delete elements from 13th to 27th elements because they are smaller than the last largest element (12th). 30th and 31st elements should be deleted because they are smaller than prior largest element (29th). Final results should contain increasing numbers. Here is the tabular representation of the data:



enter image description here



I did my best to explain my problem. Please write in the comment if it is not clear. I have a big data and I need to manipulate it as explained here. Any help would be greatly appreciated. Thanks










share|improve this question









$endgroup$








  • 4




    $begingroup$
    DeleteDuplicatesBy[ Transpose[{list[[All, 1]], FoldList[Max, list[[All, 2]]]}], Last] should do what you're after.
    $endgroup$
    – ciao
    8 hours ago










  • $begingroup$
    Should you also be deleting the second element since it is smaller than the first? I will note that the solution from @ciao does remove the second element.
    $endgroup$
    – Mark R
    7 hours ago












  • $begingroup$
    @ Mark R, yes you are right. I missed it. Thanks
    $endgroup$
    – DestinationLess_Traveller
    7 hours ago






  • 2




    $begingroup$
    DeleteDuplicates[list, #1[[2]] > #2[[2]] &]
    $endgroup$
    – Bob Hanlon
    7 hours ago










  • $begingroup$
    @ Bob, thanks for your simple answer. I really appreciate it.
    $endgroup$
    – DestinationLess_Traveller
    2 hours ago


















3












$begingroup$


Here is my list. The first column contains its index and second column has data.



list={{1, 170.93}, {2, 170.4}, {3, 174.08}, {4, 160.65}, {5, 166.44}, {6, 
169.75}, {7, 175.86}, {8, 177.6}, {9, 180.27}, {10, 182.82}, {11,
182.02}, {12, 186.65}, {13, 184.53}, {14, 186.17}, {15,
177.29}, {16, 172.06}, {17, 175.58}, {18, 168.09}, {19,
172.33}, {20, 165.1}, {21, 154.88}, {22, 161.28}, {23, 165.25}, {24,
165.15}, {25, 171.03}, {26, 174.55}, {27, 182.57}, {28,
191.02}, {29, 191.11}, {30, 184.93}, {31, 188.85}, {32, 191.44}};


I want to delete all numbers that are smaller than the last largest element. For example, I want to delete 4th, 5th and 6th elements because they are smaller than the last largest element (3rd). Similarly, I want to delete elements from 13th to 27th elements because they are smaller than the last largest element (12th). 30th and 31st elements should be deleted because they are smaller than prior largest element (29th). Final results should contain increasing numbers. Here is the tabular representation of the data:



enter image description here



I did my best to explain my problem. Please write in the comment if it is not clear. I have a big data and I need to manipulate it as explained here. Any help would be greatly appreciated. Thanks










share|improve this question









$endgroup$








  • 4




    $begingroup$
    DeleteDuplicatesBy[ Transpose[{list[[All, 1]], FoldList[Max, list[[All, 2]]]}], Last] should do what you're after.
    $endgroup$
    – ciao
    8 hours ago










  • $begingroup$
    Should you also be deleting the second element since it is smaller than the first? I will note that the solution from @ciao does remove the second element.
    $endgroup$
    – Mark R
    7 hours ago












  • $begingroup$
    @ Mark R, yes you are right. I missed it. Thanks
    $endgroup$
    – DestinationLess_Traveller
    7 hours ago






  • 2




    $begingroup$
    DeleteDuplicates[list, #1[[2]] > #2[[2]] &]
    $endgroup$
    – Bob Hanlon
    7 hours ago










  • $begingroup$
    @ Bob, thanks for your simple answer. I really appreciate it.
    $endgroup$
    – DestinationLess_Traveller
    2 hours ago














3












3








3





$begingroup$


Here is my list. The first column contains its index and second column has data.



list={{1, 170.93}, {2, 170.4}, {3, 174.08}, {4, 160.65}, {5, 166.44}, {6, 
169.75}, {7, 175.86}, {8, 177.6}, {9, 180.27}, {10, 182.82}, {11,
182.02}, {12, 186.65}, {13, 184.53}, {14, 186.17}, {15,
177.29}, {16, 172.06}, {17, 175.58}, {18, 168.09}, {19,
172.33}, {20, 165.1}, {21, 154.88}, {22, 161.28}, {23, 165.25}, {24,
165.15}, {25, 171.03}, {26, 174.55}, {27, 182.57}, {28,
191.02}, {29, 191.11}, {30, 184.93}, {31, 188.85}, {32, 191.44}};


I want to delete all numbers that are smaller than the last largest element. For example, I want to delete 4th, 5th and 6th elements because they are smaller than the last largest element (3rd). Similarly, I want to delete elements from 13th to 27th elements because they are smaller than the last largest element (12th). 30th and 31st elements should be deleted because they are smaller than prior largest element (29th). Final results should contain increasing numbers. Here is the tabular representation of the data:



enter image description here



I did my best to explain my problem. Please write in the comment if it is not clear. I have a big data and I need to manipulate it as explained here. Any help would be greatly appreciated. Thanks










share|improve this question









$endgroup$




Here is my list. The first column contains its index and second column has data.



list={{1, 170.93}, {2, 170.4}, {3, 174.08}, {4, 160.65}, {5, 166.44}, {6, 
169.75}, {7, 175.86}, {8, 177.6}, {9, 180.27}, {10, 182.82}, {11,
182.02}, {12, 186.65}, {13, 184.53}, {14, 186.17}, {15,
177.29}, {16, 172.06}, {17, 175.58}, {18, 168.09}, {19,
172.33}, {20, 165.1}, {21, 154.88}, {22, 161.28}, {23, 165.25}, {24,
165.15}, {25, 171.03}, {26, 174.55}, {27, 182.57}, {28,
191.02}, {29, 191.11}, {30, 184.93}, {31, 188.85}, {32, 191.44}};


I want to delete all numbers that are smaller than the last largest element. For example, I want to delete 4th, 5th and 6th elements because they are smaller than the last largest element (3rd). Similarly, I want to delete elements from 13th to 27th elements because they are smaller than the last largest element (12th). 30th and 31st elements should be deleted because they are smaller than prior largest element (29th). Final results should contain increasing numbers. Here is the tabular representation of the data:



enter image description here



I did my best to explain my problem. Please write in the comment if it is not clear. I have a big data and I need to manipulate it as explained here. Any help would be greatly appreciated. Thanks







list-manipulation programming






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 8 hours ago









DestinationLess_TravellerDestinationLess_Traveller

1295 bronze badges




1295 bronze badges








  • 4




    $begingroup$
    DeleteDuplicatesBy[ Transpose[{list[[All, 1]], FoldList[Max, list[[All, 2]]]}], Last] should do what you're after.
    $endgroup$
    – ciao
    8 hours ago










  • $begingroup$
    Should you also be deleting the second element since it is smaller than the first? I will note that the solution from @ciao does remove the second element.
    $endgroup$
    – Mark R
    7 hours ago












  • $begingroup$
    @ Mark R, yes you are right. I missed it. Thanks
    $endgroup$
    – DestinationLess_Traveller
    7 hours ago






  • 2




    $begingroup$
    DeleteDuplicates[list, #1[[2]] > #2[[2]] &]
    $endgroup$
    – Bob Hanlon
    7 hours ago










  • $begingroup$
    @ Bob, thanks for your simple answer. I really appreciate it.
    $endgroup$
    – DestinationLess_Traveller
    2 hours ago














  • 4




    $begingroup$
    DeleteDuplicatesBy[ Transpose[{list[[All, 1]], FoldList[Max, list[[All, 2]]]}], Last] should do what you're after.
    $endgroup$
    – ciao
    8 hours ago










  • $begingroup$
    Should you also be deleting the second element since it is smaller than the first? I will note that the solution from @ciao does remove the second element.
    $endgroup$
    – Mark R
    7 hours ago












  • $begingroup$
    @ Mark R, yes you are right. I missed it. Thanks
    $endgroup$
    – DestinationLess_Traveller
    7 hours ago






  • 2




    $begingroup$
    DeleteDuplicates[list, #1[[2]] > #2[[2]] &]
    $endgroup$
    – Bob Hanlon
    7 hours ago










  • $begingroup$
    @ Bob, thanks for your simple answer. I really appreciate it.
    $endgroup$
    – DestinationLess_Traveller
    2 hours ago








4




4




$begingroup$
DeleteDuplicatesBy[ Transpose[{list[[All, 1]], FoldList[Max, list[[All, 2]]]}], Last] should do what you're after.
$endgroup$
– ciao
8 hours ago




$begingroup$
DeleteDuplicatesBy[ Transpose[{list[[All, 1]], FoldList[Max, list[[All, 2]]]}], Last] should do what you're after.
$endgroup$
– ciao
8 hours ago












$begingroup$
Should you also be deleting the second element since it is smaller than the first? I will note that the solution from @ciao does remove the second element.
$endgroup$
– Mark R
7 hours ago






$begingroup$
Should you also be deleting the second element since it is smaller than the first? I will note that the solution from @ciao does remove the second element.
$endgroup$
– Mark R
7 hours ago














$begingroup$
@ Mark R, yes you are right. I missed it. Thanks
$endgroup$
– DestinationLess_Traveller
7 hours ago




$begingroup$
@ Mark R, yes you are right. I missed it. Thanks
$endgroup$
– DestinationLess_Traveller
7 hours ago




2




2




$begingroup$
DeleteDuplicates[list, #1[[2]] > #2[[2]] &]
$endgroup$
– Bob Hanlon
7 hours ago




$begingroup$
DeleteDuplicates[list, #1[[2]] > #2[[2]] &]
$endgroup$
– Bob Hanlon
7 hours ago












$begingroup$
@ Bob, thanks for your simple answer. I really appreciate it.
$endgroup$
– DestinationLess_Traveller
2 hours ago




$begingroup$
@ Bob, thanks for your simple answer. I really appreciate it.
$endgroup$
– DestinationLess_Traveller
2 hours ago










1 Answer
1






active

oldest

votes


















4












$begingroup$

TakeList[list, Length /@ Split[FoldList[Max, list[[All, 2]]]]][[All, 1]]



{{1, 170.93}, {3, 174.08}, {7, 175.86}, {8, 177.6}, {9, 180.27}, {10,
182.82}, {12, 186.65}, {28, 191.02}, {29, 191.11}, {32, 191.44}}




Also



max = list[[1, -1]];
Split[list, Or[Last[#2] < max, max = Last[#2]] &][[All, 1]]



same result




DeleteDuplicates[Join @@ FoldList[MaximalBy[Last] @* Append, {First @ list}, 
Rest @ list]]



same result




The first method is much faster.






share|improve this answer











$endgroup$













  • $begingroup$
    Thank you kglr.
    $endgroup$
    – DestinationLess_Traveller
    6 hours ago










  • $begingroup$
    @DestinationLess_Traveller, thank you for the accept.
    $endgroup$
    – kglr
    6 hours ago














Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201662%2fdelete-elements-less-than-the-last-largest-element%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4












$begingroup$

TakeList[list, Length /@ Split[FoldList[Max, list[[All, 2]]]]][[All, 1]]



{{1, 170.93}, {3, 174.08}, {7, 175.86}, {8, 177.6}, {9, 180.27}, {10,
182.82}, {12, 186.65}, {28, 191.02}, {29, 191.11}, {32, 191.44}}




Also



max = list[[1, -1]];
Split[list, Or[Last[#2] < max, max = Last[#2]] &][[All, 1]]



same result




DeleteDuplicates[Join @@ FoldList[MaximalBy[Last] @* Append, {First @ list}, 
Rest @ list]]



same result




The first method is much faster.






share|improve this answer











$endgroup$













  • $begingroup$
    Thank you kglr.
    $endgroup$
    – DestinationLess_Traveller
    6 hours ago










  • $begingroup$
    @DestinationLess_Traveller, thank you for the accept.
    $endgroup$
    – kglr
    6 hours ago
















4












$begingroup$

TakeList[list, Length /@ Split[FoldList[Max, list[[All, 2]]]]][[All, 1]]



{{1, 170.93}, {3, 174.08}, {7, 175.86}, {8, 177.6}, {9, 180.27}, {10,
182.82}, {12, 186.65}, {28, 191.02}, {29, 191.11}, {32, 191.44}}




Also



max = list[[1, -1]];
Split[list, Or[Last[#2] < max, max = Last[#2]] &][[All, 1]]



same result




DeleteDuplicates[Join @@ FoldList[MaximalBy[Last] @* Append, {First @ list}, 
Rest @ list]]



same result




The first method is much faster.






share|improve this answer











$endgroup$













  • $begingroup$
    Thank you kglr.
    $endgroup$
    – DestinationLess_Traveller
    6 hours ago










  • $begingroup$
    @DestinationLess_Traveller, thank you for the accept.
    $endgroup$
    – kglr
    6 hours ago














4












4








4





$begingroup$

TakeList[list, Length /@ Split[FoldList[Max, list[[All, 2]]]]][[All, 1]]



{{1, 170.93}, {3, 174.08}, {7, 175.86}, {8, 177.6}, {9, 180.27}, {10,
182.82}, {12, 186.65}, {28, 191.02}, {29, 191.11}, {32, 191.44}}




Also



max = list[[1, -1]];
Split[list, Or[Last[#2] < max, max = Last[#2]] &][[All, 1]]



same result




DeleteDuplicates[Join @@ FoldList[MaximalBy[Last] @* Append, {First @ list}, 
Rest @ list]]



same result




The first method is much faster.






share|improve this answer











$endgroup$



TakeList[list, Length /@ Split[FoldList[Max, list[[All, 2]]]]][[All, 1]]



{{1, 170.93}, {3, 174.08}, {7, 175.86}, {8, 177.6}, {9, 180.27}, {10,
182.82}, {12, 186.65}, {28, 191.02}, {29, 191.11}, {32, 191.44}}




Also



max = list[[1, -1]];
Split[list, Or[Last[#2] < max, max = Last[#2]] &][[All, 1]]



same result




DeleteDuplicates[Join @@ FoldList[MaximalBy[Last] @* Append, {First @ list}, 
Rest @ list]]



same result




The first method is much faster.







share|improve this answer














share|improve this answer



share|improve this answer








edited 7 hours ago

























answered 7 hours ago









kglrkglr

203k10 gold badges232 silver badges463 bronze badges




203k10 gold badges232 silver badges463 bronze badges












  • $begingroup$
    Thank you kglr.
    $endgroup$
    – DestinationLess_Traveller
    6 hours ago










  • $begingroup$
    @DestinationLess_Traveller, thank you for the accept.
    $endgroup$
    – kglr
    6 hours ago


















  • $begingroup$
    Thank you kglr.
    $endgroup$
    – DestinationLess_Traveller
    6 hours ago










  • $begingroup$
    @DestinationLess_Traveller, thank you for the accept.
    $endgroup$
    – kglr
    6 hours ago
















$begingroup$
Thank you kglr.
$endgroup$
– DestinationLess_Traveller
6 hours ago




$begingroup$
Thank you kglr.
$endgroup$
– DestinationLess_Traveller
6 hours ago












$begingroup$
@DestinationLess_Traveller, thank you for the accept.
$endgroup$
– kglr
6 hours ago




$begingroup$
@DestinationLess_Traveller, thank you for the accept.
$endgroup$
– kglr
6 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematica Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201662%2fdelete-elements-less-than-the-last-largest-element%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Ciclooctatetraenă Vezi și | Bibliografie | Meniu de navigare637866text4148569-500570979m