Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Bins data in to lists based on applying a function to each item.
ResourceFunction["BinListsBy"][{x1,x2,…},{f,xmin,xmax}] gives lists of the elements xi for which the values of f[xi] lie in bins from xmin to xmax with unit width. |
|
ResourceFunction["BinListsBy"][{x1,x2,…},{f,xmin,xmax,Δx}] gives lists of the elements xi for which the values of f[xi] lie in bins from xmin to xmax with width Δx. |
|
ResourceFunction["BinListsBy"][{x1,x2,…},binspec1,binspec2,…] gives an array of lists of the elements xi for which each index is determined by applying fi of the binning specifications binspeci to the value xi. |
Bin some data based only on the first element of each list:
In[1]:= |
![]() |
Out[2]= |
![]() |
Bin a list of data based on the string length of each item:
In[3]:= |
![]() |
Out[4]= |
![]() |
Bin some data based on the total of each list:
In[5]:= |
![]() |
Out[6]= |
![]() |
Bin some data with some ‘auxiliary’ data:
In[7]:= |
![]() |
Out[8]= |
![]() |
Perform a 2 dimensional binning based on the value of the first element, and the string length of the last element:
In[9]:= |
![]() |
Out[11]= |
![]() |
Perform a 3 dimensional binning based on the value of the first element, the value of the middle element, and the length of the last element:
In[12]:= |
![]() |
Out[13]= |
![]() |
The lists do not need to have the same length, structure, or type, allowing to bin data with auxiliary data:
In[14]:= |
![]() |
Out[15]= |
![]() |
Bin some data based on the number of unique letters in each string:
In[16]:= |
![]() |
Out[17]= |
![]() |
Bin complex numbers based on their imaginary and real parts:
In[18]:= |
![]() |
Out[21]= |
![]() |
Bin some strings based on their first letter:
In[22]:= |
![]() |
Out[24]= |
![]() |
Bin some person entities based on their birth century:
In[25]:= |
![]() |
Out[27]= |
![]() |
Bin some associations based on age:
In[28]:= |
![]() |
Out[29]= |
![]() |
BinLists can sometimes perform similar tasks as BinListsBy by giving a single large bin in the ‘other’ dimensions:
In[30]:= |
![]() |
Out[31]= |
![]() |
GatherBy gives similar output as BinListsBy, but BinListsBy always returns an output with the same dimensions, the bins are sorted, and includes empty lists where necessary:
In[32]:= |
![]() |
In[33]:= |
![]() |
Out[33]= |
![]() |
In[34]:= |
![]() |
Out[34]= |
![]() |
Explicitly check they return the same:
In[35]:= |
![]() |
Out[35]= |
![]() |
If the function does not return a number it will not be binned:
In[36]:= |
![]() |
Out[37]= |
![]() |
Values outside the binning range are discarded:
In[38]:= |
![]() |
Out[39]= |
![]() |
Bin some datasets based on their regressed slope:
In[40]:= |
![]() |
Out[42]= |
![]() |
Plot the datasets with similar slopes together:
In[43]:= |
![]() |
Out[43]= |
![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License