1
$\begingroup$

The data:

{{9.99758, 0}, {"", ""}, {10.0178, -21.7137}, {"", ""}, {10.038, 
  28.5723}, {"", ""}, {10.0582, 0.52409}, {"", ""}, {10.0784, 
  21.7378}, {"", ""}, {10.0987, 0}, {"", ""},...}

I need to remove the empty points, i.e. the {"", ""}, parts. I either need to find that pattern and remove it or simply remove every other point in this list.

In attempting to remove by pattern, I tried doing data /. Part[data, 2] -> "" but this returned:

{{9.99758, 0}, "", {10.0178, -21.7137}, "", {10.038, 
  28.5723}, "", {10.0582, 0.52409}, "", {10.0784, 
  21.7378}, "", {10.0987, 0}, "", {10.1189, 3.13778}, "",...}

How would I then finish it off by removing the "", part?

$\endgroup$
2
  • $\begingroup$ Never mind, I just figured it out. It's simply data[[1;; ;; 2]] $\endgroup$ Oct 12, 2017 at 22:36
  • 1
    $\begingroup$ DeleteCases[{data, {"", ""}] $\endgroup$
    – user1066
    Oct 12, 2017 at 23:42

1 Answer 1

2
$\begingroup$

Preparation

lst = {{9.99758, 0}, {"", ""}, {10.0178, -21.7137}, {"", ""}, {10.038, 28.5723}, {"", ""}, {10.0582, 0.52409}, {"", ""}, {10.0784, 21.7378}, {"", ""}, {10.0987, 0}, {"", ""}};

Solution 1

As @tomd pointed, you can:

DeleteCases[lst, {"", ""}]
(* ==> {{9.99758, 0}, {10.0178, -21.7137}, {10.038, 28.5723}, {10.0582, 0.52409}, {10.0784, 21.7378}, {10.0987, 0}} *)

Solution 2

Or else, you can still use Pattern Replace by:

lst /. {"", ""} -> Sequence[] 
(* ==> {{9.99758, 0}, {10.0178, -21.7137}, {10.038, 28.5723}, {10.0582, 0.52409}, {10.0784, 21.7378}, {10.0987, 0}} *)
$\endgroup$
2
  • 2
    $\begingroup$ {"", ""} -> Nothing works in newer versions. $\endgroup$ Oct 13, 2017 at 4:47
  • $\begingroup$ @J.M. It works! Thank you! I know one more thing! $\endgroup$
    – PureLine
    Oct 13, 2017 at 4:49

Your Answer

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

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