Delete elements less than the last largest elementDeleting 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?
How should I ask for a "pint" in countries that use metric?
Why did Old English lose both thorn and eth?
Did depressed people far more accurately estimate how many monsters they killed in a video game?
stuck in/at beta
How does one acquire an undead eyeball encased in a gem?
Blocks from @ jafe
Why do people prefer metropolitan areas, considering monsters and villains?
Compute Manhattan distance from origin given a set of left-right-step directions
Computer name naming convention for security
Deck of Cards with Shuffle and Sort functionality
Is "wissen" the only verb in German to have an irregular present tense?
Why am I getting unevenly-spread results when using $RANDOM?
With a data transfer of 50 GB estimated 5 hours, are USB-C claimed speeds inaccurate or to blame?
What is the relationship between external and internal composition in a cartesian closed category?
Why does Trump want a citizenship question on the census?
Delete elements less than the last largest element
Tikz people in diagram
Is it ok for parents to kiss and romance with each other while their 2- to 8-year-old child watches?
Who goes first? Person disembarking bus or the bicycle?
Sense of humor in your sci-fi stories
Category-theoretic treatment of diffs, patches and merging?
Test Driven Development Roman Numerals php
Why won't the U.S. sign a peace treaty with North Korea?
How do resistors generate different heat if we make the current fixed and changed the voltage and resistance? Notice the flow of charge is constant
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;
$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:
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
$endgroup$
add a comment |
$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:
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
$endgroup$
4
$begingroup$
DeleteDuplicatesBy[ Transpose[list[[All, 1]], FoldList[Max, list[[All, 2]]]], Last]
should do what you're after.
$endgroup$
– ciao
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
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
add a comment |
$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:
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
$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:
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
list-manipulation programming
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
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
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
add a comment |
4
$begingroup$
DeleteDuplicatesBy[ Transpose[list[[All, 1]], FoldList[Max, list[[All, 2]]]], Last]
should do what you're after.
$endgroup$
– ciao
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
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
7 hours ago
$begingroup$
DeleteDuplicatesBy[ Transpose[list[[All, 1]], FoldList[Max, list[[All, 2]]]], Last]
should do what you're after.$endgroup$
– ciao
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$
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
add a comment |
1 Answer
1
active
oldest
votes
$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.
$endgroup$
$begingroup$
Thank you kglr.
$endgroup$
– DestinationLess_Traveller
6 hours ago
$begingroup$
@DestinationLess_Traveller, thank you for the accept.
$endgroup$
– kglr
6 hours ago
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$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.
$endgroup$
$begingroup$
Thank you kglr.
$endgroup$
– DestinationLess_Traveller
6 hours ago
$begingroup$
@DestinationLess_Traveller, thank you for the accept.
$endgroup$
– kglr
6 hours ago
add a comment |
$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.
$endgroup$
$begingroup$
Thank you kglr.
$endgroup$
– DestinationLess_Traveller
6 hours ago
$begingroup$
@DestinationLess_Traveller, thank you for the accept.
$endgroup$
– kglr
6 hours ago
add a comment |
$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.
$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.
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
add a comment |
$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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
4
$begingroup$
DeleteDuplicatesBy[ Transpose[list[[All, 1]], FoldList[Max, list[[All, 2]]]], Last]
should do what you're after.$endgroup$
– ciao
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
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