# Removing complex numbers from a set

I have the following list:

{{-1628.11740799393 - 557.339672450634 I}, {-1628.11740799393 + 557.339672450634 I},
{-920.324284271774 - 1508.13304084624 I}, {-920.324284271774 + 1508.13304084624 I},
{2107.28351459532}, {2145.53211042304}, {2207.19944421678}, {2289.69932193979},
{2318.0488541237 - 13.4030555095579 I}, {2318.0488541237 + 13.4030555095579 I}}


I would like to remove the complex numbers (Real & Imaginary parts) from this set and keep the real sets only which are 4 subsets in this case. I really appreciate any help in this regard.

alist = {-1628.12 - 557.34 I, -1628.12 + 557.34 I, -920.324 -
1508.13 I, -920.324 + 1508.13 I, 2107.28, 2145.53, 2207.2, 2289.7,
2318.05 - 13.4031 I, 2318.05 + 13.4031 I}

Cases[alist, Except@_Complex]


{2107.28, 2145.53, 2207.2, 2289.7}

Try Select

list={-1628.12 - 557.34 I, -1628.12 + 557.34 I, -920.324 - 1508.13 I, -920.324 + 1508.13 I, 2107.28, 2145.53, 2207.2, 2289.7,2318.05 - 13.4031 I, 2318.05 + 13.4031 I}

Select[list, Im[#] == 0 &]
(*{2107.28, 2145.53, 2207.2, 2289.7}*)

• It worked! Thanks so much @Ulrich Neumann...
– Naps
Commented Sep 1, 2021 at 10:21
• You're welcome! Commented Sep 1, 2021 at 10:21

Try DeleteCases:

list={-1628.12 - 557.34 I, -1628.12 + 557.34 I, -920.324 - 1508.13 I,-920.324 + 1508.13 I, 2107.28, 2145.53, 2207.2, 2289.7,2318.05 - 13.4031 I, 2318.05 + 13.4031 I}
DeleteCases[list, _Complex]
(*{2107.28, 2145.53, 2207.2, 2289.7}*)


With appended Integer and Rational:

list =
{-1628.12 - 557.34 I, -1628.12 + 557.34 I, -920.324 -
1508.13 I, -920.324 + 1508.13 I, 2107.28, 2145.53, 2207.2, 2289.7,
2318.05 - 13.4031 I, 2318.05 + 13.4031 I, 99, 3/4};

Pick[list, RealValuedNumberQ /@ list]


{2107.28, 2145.53, 2207.2, 2289.7, 99, 3/4}

Compare to

Pick[list, MatchQ[_Real] /@ list]


{2107.28, 2145.53, 2207.2, 2289.7}

RealValuedNumberQ came with V 13.3