KeyUnion
Details
- KeyUnion returns a list of associations in which all the associations have keys ordered in the same way.
- If f is an association containing all the keys to be returned by KeyUnion, then the order of keys in f will determine the order of keys in the associations returned.
- In other cases, the keys will appear in order of their first occurrence in the sequence of associ.
- KeyUnion can be used not only on Association objects, but also on lists of rules.
Examples
Basic Examples (4)
Make a list of associations with the same keys:
KeyUnion[{<|a -> 1, b -> 2|>, <|b -> 3|>}]Reorder the keys of all associations:
KeyUnion[{<|a -> 1, b -> 2, c -> 3|>, <|c -> z, a -> x, b -> y|>}]Use a function to provide missing values:
KeyUnion[{<|a -> 1, b -> 2, c -> 3|>, <|b -> y|>}, # ^ 2&]The missing function can be an association:
KeyUnion[{<|a -> 1, b -> 2|>, <|c -> 3|>}, <|a -> x, b -> y, c -> z|>]See Also
Related Guides
History
Text
Wolfram Research (2014), KeyUnion, Wolfram Language function, https://reference.wolfram.com/language/ref/KeyUnion.html.
CMS
Wolfram Language. 2014. "KeyUnion." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/KeyUnion.html.
APA
Wolfram Language. (2014). KeyUnion. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/KeyUnion.html
BibTeX
@misc{reference.wolfram_2026_keyunion, author="Wolfram Research", title="{KeyUnion}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/KeyUnion.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_keyunion, organization={Wolfram Research}, title={KeyUnion}, year={2014}, url={https://reference.wolfram.com/language/ref/KeyUnion.html}, note=[Accessed: 13-June-2026]}