3
$\begingroup$

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.

$\endgroup$

4 Answers 4

5
$\begingroup$
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}

$\endgroup$
4
$\begingroup$

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}*)
$\endgroup$
2
  • $\begingroup$ It worked! Thanks so much @Ulrich Neumann... $\endgroup$
    – Naps
    Sep 1, 2021 at 10:21
  • $\begingroup$ You're welcome! $\endgroup$ Sep 1, 2021 at 10:21
4
$\begingroup$

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}*)
$\endgroup$
1
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.