Discard

Discard[data,crit]

removes all the elements ei of data for which crit[ei] is True.

Discard[data,critprop]

returns the property prop of the remaining elements.

Discard[data,crit,n]

removes the first n elements for which crit[ei] is True.

Discard[crit]

represents an operator form of Discard that can be applied to an expression.

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 »
    Allan association giving element, index and bit vector mask »
  • Discard[crit][data] is equivalent to Discard[data,crit].

Examples

open allclose all

Basic 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 pairs containing x:

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:

Use Discard on a Tabular object with named columns:

Discard rows with last column date being a business day:

Property Forms  (5)

Return the remaining elements:

Return the indices of the remaining elements:

Return the Boolean mask of the data:

Return two forms:

Return the association with all the properties:

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:

Remove the rows with at least two missing values:

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:

Possible Issues  (2)

Discard drops elements for which applying the criterion explicitly yields True:

The symbolic object x is included in both cases, since neither inequality gives True:

The head of the input expression is only preserved for the default "Element" property:

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

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

BibTeX

@misc{reference.wolfram_2024_discard, author="Wolfram Research", title="{Discard}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/Discard.html}", note=[Accessed: 15-January-2025 ]}

BibLaTeX

@online{reference.wolfram_2024_discard, organization={Wolfram Research}, title={Discard}, year={2025}, url={https://reference.wolfram.com/language/ref/Discard.html}, note=[Accessed: 15-January-2025 ]}