Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
For each element of a list, find the index of the next greater element
ResourceFunction["NextGreaterElementIndex"][list] for each element of list, find the index of the next numerically greater element. | |
ResourceFunction["NextGreaterElementIndex"][list,p] find the indices using order function p. |
Visualize the input data:
| In[1]:= |
| Out[2]= | ![]() |
The indices of the next greater elements:
| In[3]:= |
| Out[3]= |
Except for columns ending in -1, each second item is the next greater element:
| In[4]:= |
| Out[4]= | ![]() |
For non-numeric input, one may use customized order function:
| In[5]:= |
| Out[6]= | ![]() |
For instance the sixth item in the date list, , is the next later day than :
| In[7]:= |
| Out[7]= |
Comparable Quantity objects are supported:
| In[8]:= | ![]() |
| In[9]:= |
| Out[9]= |
Check the index of each next greater item visually:
| In[10]:= |
| Out[10]= | ![]() |
Collect and show data for a stock:
| In[11]:= |
| In[12]:= |
| Out[12]= | ![]() |
Find the wait time to observe an overshoot in stock price for a given duration:
| In[13]:= |
| Out[14]= |
Tabulate the current price and next high:
| In[15]:= | ![]() |
| Out[15]= | ![]() |
An empty input list returns an empty list:
| In[16]:= |
| Out[16]= |
A single element list returns {-1}:
| In[17]:= |
| Out[17]= |
The single argument input must be a list of real valued numeric values. Otherwise the function returns unevaluated:
| In[18]:= |
| Out[18]= |
For non-comparable items, Order is applied automatically:
| In[19]:= |
| Out[19]= |
| In[20]:= |
| Out[20]= |
Wolfram Language 14.0 (January 2024) or above
This work is licensed under a Creative Commons Attribution 4.0 International License