Discard
Discard[data,critprop]
returns the property prop of the remaining elements.
Details
- Discard keeps the elements for which the given criterion crit is False.
- The data can have the following additional forms and interpretations:
-
{e1,e2,…} list of values » f[e1,e2,…] any head f » Association[…] association of values » QuantityArray[…] quantity array or other structured array Tabular[…] type-consistent tabular data » TabularColumn[…] type-consistent column data » Dataset[…] general hierarchical data - The property prop can have the following forms and interpretations:
-
"Element" the remaining values » "Index" indices of the remaining values » "BitVectorMask" Boolean mask returning True for selected values and False otherwise » {prop1,prop2,…} a list of multiple forms » All an association giving element, index and bit vector mask » - Discard[crit][data] is equivalent to Discard[data,crit].
Examples
open allclose allBasic Examples (6)
Discard elements that are even:
Return the indices of the remaining elements:
Discard only the first expression selected:
Use the operator form of Discard:
Discard operates on values in an Association:
Discard rows in a Tabular object:
Scope (15)
Basic Uses (5)
Remove up to two pairs containing x:
Use a pure function to test each element:
Use an operator form as selection criterion:
Use Discard in operator form:
Input Data (5)
Discard works with any head, not just List:
Discard works on values in Association:
Discard works with vector SparseArray objects:
The result may be a list if it is not sparse:
Discard works with TabularColumn objects:
Remove all dates with even days:
The distribution of the dates is uniform:
Applications (8)
Discard numbers up to 100 that are divisible by 4:
Discard the first 3 of 4-tuples that read the same in reverse:
Discard 3×3 matrices of 0s and 1s that have determinant less than 2:
Discard eigenvalues that lie within the unit circle:
Find built-in Wolfram Language objects whose names are at least 36 characters long:
Remove numeric quantities from a product:
Find an approximation to by finding the proportion of points that lie within a disk:
Weather data from JFK airport:
Use TabularStructure to investigate the number of missing data:
Properties & Relations (3)
Discard is complementary to Select:
Discard is similar to Cases except that it uses a function instead of a pattern:
Discard the lists that have a sum of elements greater than 10:
Use Cases to get the same result:
Discard elements that are even:
Use GatherBy to separate odd and even elements:
Use GroupBy to construct an association explicitly containing as keys the results of the criterion:
Text
Wolfram Research (2025), Discard, Wolfram Language function, https://reference.wolfram.com/language/ref/Discard.html.
CMS
Wolfram Language. 2025. "Discard." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Discard.html.
APA
Wolfram Language. (2025). Discard. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Discard.html