Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Similar to AssociationMap but maps over a given set of values to obtain keys rather than vice versa
ResourceFunction["ValueMap"][func,x] creates an Association in which the keys are the mapping of func over x and the values are x. | |
ResourceFunction["ValueMap"][func] an operator form that, when presented with a list of values x, will create ResourceFunction["ValueMap"][func,x]. |
Create keys by mapping symbolic function f over a list of strings:
In[1]:= |
Out[1]= |
Create an Association between hashes of the values and the values themselves:
In[2]:= |
Out[2]= |
ValueMap works on the first level of expressions:
In[3]:= |
Out[3]= |
Work on lower levels by using Map in conjunction with ValueMap:
In[4]:= |
Out[4]= |
ValueMap works with Query on datasets:
In[5]:= |
Out[5]= |
It also works with implicit Query operations:
In[6]:= |
Out[6]= |
Create row headers for the Paul Revere social network based on the name of the person involved:
In[7]:= |
Out[7]= |
One can accomplish much the same thing as ValueMap with the following code that uses AssociationMap; however, it is quite cumbersome:
In[8]:= |
Out[8]= |
If the key generated from application of the function is not unique, the value for that key will be the last value encountered that generated the key:
In[9]:= |
Out[9]= |
Sometimes, this deletion of key-value pairs with duplicate keys may be exactly what is desired, however:
In[10]:= |
Out[10]= |
ValueMap will not work properly on datasets without the use of Query:
In[11]:= |
Out[11]= |
Use ValueMap to create a custom index on the hash of a function of two columns of a dataset and then use the index to swiftly retrieve information:
In[12]:= |
Out[12]= |
This work is licensed under a Creative Commons Attribution 4.0 International License