SplitBy
Details
- SplitBy[list,…] splits but does not rearrange list.
- SplitBy performs comparisons only on adjacent pairs of elements.
- SplitBy[list,Identity] is equivalent to Split[list]. »
- SplitBy[list,{f1,f2}] is equivalent to Map[SplitBy[#,f2]&,SplitBy[list,f1]]. »
- SplitBy[f][list] is equivalent to SplitBy[list,f]. »
Examples
open all close allBasic Examples (2)
Scope (4)
SplitBy[Range[10], Quotient[#, 3]&]Split into runs of triples with identical first component:
SplitBy[Tuples[{1, 2}, 3], First]Split first by their first component and then by their second:
SplitBy[Tuples[{1, 2}, 3], {First, Part[#, 2]&}]Use Framed to display grouping:
Map[Framed, %, {1, 2}]Define a SplitBy operator:
op = SplitBy[Last];Use the operator to split integer data, putting each group on a separate row of a column:
ints = RandomInteger[4, {10, 3}];
op[ints]//ColumnUse the operator to split string data:
words = RandomChoice[RandomWord[5], {10, 2}];
op[words]//ColumnCreate a list of associations:
data = Table[AssociationThread[CharacterRange["a", "c"] -> RandomInteger[1, 3]], {10}]Split by the value of the key "a":
Framed /@ SplitBy[data, #a&]Gather by the value of the keys "a" and "b", using the operator form of GatherBy:
Map[Framed, SplitBy[{#a&, #b&}][data], {1, 2}]Applications (1)
Properties & Relations (4)
SplitBy[expr,Identity] and Split[expr] are the same operation:
SplitBy[{a, a, a, b, b, a, a, c}, Identity] === Split[{a, a, a, b, b, a, a, c}]SplitBy[list,f] is equivalent to Split[list,(f[#1]===f[#2])&]:
m = RandomInteger[1, {10, 5}];
SplitBy[m, Norm] == Split[m, (Norm[#1] === Norm[#2])&]Display the groups along with the norm of each group:
Grid[Map[{MatrixForm[#], Norm[First[#]]}&, SplitBy[m, Norm] ]]SplitBy[list,{f1,f2}] is equivalent to Map[SplitBy[#,f2]&,SplitBy[list,f1]]:
list = RandomInteger[{-4, 4}, 9];
SplitBy[list, {Positive, EvenQ}] === Map[SplitBy[#, EvenQ]&, SplitBy[list, Positive]]SplitBy[f][list] is equivalent to SplitBy[list,f]:
list = Range[-4, 4];
SplitBy[Positive][list] === SplitBy[list, Positive]See Also
Split GatherBy DeleteAdjacentDuplicates SequenceSplit Partition SortBy
Function Repository: SplitWhen SplitByPatterns SplitAt
Related Guides
Text
Wolfram Research (2008), SplitBy, Wolfram Language function, https://reference.wolfram.com/language/ref/SplitBy.html (updated 2026).
CMS
Wolfram Language. 2008. "SplitBy." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2026. https://reference.wolfram.com/language/ref/SplitBy.html.
APA
Wolfram Language. (2008). SplitBy. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SplitBy.html
BibTeX
@misc{reference.wolfram_2026_splitby, author="Wolfram Research", title="{SplitBy}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/SplitBy.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_splitby, organization={Wolfram Research}, title={SplitBy}, year={2026}, url={https://reference.wolfram.com/language/ref/SplitBy.html}, note=[Accessed: 12-June-2026]}