I'm trying to update the value of a field in all records of a dataset by applying a function to the value of the field. I had no luck working with a dataset, so I converted the dataset to a list of associations and mapped AssociateTo. However, I always get the error message "is not a variable with a value, so its value cannot be changed." I checked with chapGPT with a simpler problem, and it gave me this code as an example
list = {<|"a" -> 1, "b" -> 2|>, <|"c" -> 3, "d" -> 4|>}
Map[AssociateTo[#, "e" -> 5]&, list]
(* Output: {<|"a" -> 1, "b" -> 2, "e" -> 5|>, <|"c" -> 3, "d" -> 4, "e" -> 5|>} *)
However, this code returns the same error.
list = {<|"a" -> 1, "b" -> 2|>, <|"c" -> 3, "d" -> 4|>};
Map[AssociateTo[#, "e" -> 5] &, list]
During evaluation of In[149]:= AssociateTo::rvalue: <|a->1,b->2|> is not a variable with a value, so its value cannot be changed.
During evaluation of In[149]:= AssociateTo::rvalue: <|c->3,d->4|> is not a variable with a value, so its value cannot be changed.
Out[150]= {AssociateTo[<|"a" -> 1, "b" -> 2|>, "e" -> 5],
AssociateTo[<|"c" -> 3, "d" -> 4|>, "e" -> 5]}
I'd appreciate any advice. Thanks