Wolfram Function Repository
Instantuse addon functions for the Wolfram Language
Function Repository Resource:
Bin data into lists based on applying a function to each item
ResourceFunction["BinListsBy"][{x_{1},x_{2},…},{f,x_{min},x_{max}}] gives lists of the elements x_{i} for which the values of f[x_{i}] lie in bins from x_{min} to x_{max} with unit width. 

ResourceFunction["BinListsBy"][{x_{1},x_{2},…},{f,x_{min},x_{max},Δx}] gives lists of the elements x_{i} for which the values of f[x_{i}] lie in bins from x_{min} to x_{max} with width Δx. 

ResourceFunction["BinListsBy"][{x_{1},x_{2},…},binspec_{1},binspec_{2},…] gives an array of lists of the elements x_{i} for which each index is determined by applying f_{i} of the binning specifications binspec_{i} to the value x_{i}. 
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