Gather

Gather[list]

gathers the elements of list into sublists of identical elements.

Gather[list,test]

applies test to pairs of elements to determine if they should be considered identical.

Details

  • The default function used to test whether elements are identical is SameQ.
  • Gather[{e1,e2,},p] will gather together elements for which p[ei,ej] returns True.

Examples

open allclose all

Basic Examples  (2)

Gather elements into sublists of identical elements:

Gather elements that have identical first parts:

Applications  (3)

Gather elements that have equal integer parts:

Gather integers that have identical remainders:

Gather polynomials that have identical remainders:

Properties & Relations  (2)

DeleteDuplicates[list] is equivalent to Gather[list][[All,1]]:

For a large list, DeleteDuplicates is much faster:

GatherBy[list,f] is equivalent to Gather[list,(f[#1]===f[#2])&]:

Gather the rows by Norm and display with the common norm of each group:

Compare to the result of Gather:

Possible Issues  (1)

When the test cannot be identified as an equality comparison, Gather may be much slower:

The results are identical:

Wolfram Research (2008), Gather, Wolfram Language function, https://reference.wolfram.com/language/ref/Gather.html.

Text

Wolfram Research (2008), Gather, Wolfram Language function, https://reference.wolfram.com/language/ref/Gather.html.

CMS

Wolfram Language. 2008. "Gather." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Gather.html.

APA

Wolfram Language. (2008). Gather. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Gather.html

BibTeX

@misc{reference.wolfram_2024_gather, author="Wolfram Research", title="{Gather}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/Gather.html}", note=[Accessed: 21-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_gather, organization={Wolfram Research}, title={Gather}, year={2008}, url={https://reference.wolfram.com/language/ref/Gather.html}, note=[Accessed: 21-December-2024 ]}