Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Get the proportion of times that each distinct element appears in a list when evaluated with a given function
ResourceFunction["ProportionsBy"][{e1,e2,…},f] gives an association whose keys are the distinct values of the f[ei] and whose values give the proportion of times these f[ei] values appear. | |
ResourceFunction["ProportionsBy"][f] represents an operator form of ResourceFunction["ProportionsBy"] that can be applied to an expression. |
Determine the proportion of a list of integers that is EvenQ:
In[1]:= | ![]() |
Out[1]= | ![]() |
Get the proportion of a list that is PrimeQ:
In[2]:= | ![]() |
Out[2]= | ![]() |
Use with an Association:
In[3]:= | ![]() |
Out[3]= | ![]() |
Use the operator form of ProportionsBy:
In[4]:= | ![]() |
Out[4]= | ![]() |
In[5]:= | ![]() |
Out[5]= | ![]() |
See how common each character is in a body of text while ignoring case:
In[6]:= | ![]() |
Out[6]= | ![]() |
Check for common words:
In[7]:= | ![]() |
Out[7]= | ![]() |
In[8]:= | ![]() |
Out[8]= | ![]() |
Visualize in a WordCloud:
In[9]:= | ![]() |
Out[9]= | ![]() |
The result of ProportionsBy is identical to that of the resource function Proportions applied to the results of Map:
In[10]:= | ![]() |
Out[10]= | ![]() |
In[11]:= | ![]() |
Out[11]= | ![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License