5
$\begingroup$

MyDataSet[Select[#point[Fsr] == 1 &]] returns the row I want to delete, now I am trying what looks to me the most logic command to remove these rows, which is MyDataSet[Delete[#point[Fsr] == 1 &]] MyDataSet[DeleteCases[#point[Fsr] == 1 &]], but neither works .... any idea how this should be done?

$\endgroup$
  • 4
    $\begingroup$ What does MyDataSet[Select[#point[Fsr] != 1 &]] do? $\endgroup$ – J. M. will be back soon Oct 26 '15 at 23:25
  • $\begingroup$ ... undeniably it gives me a new dataset without the rows I wanted to remove, but I have two concerns about this method: 1) for a large dataset, isn't it better to pullout what you do not need (a few items) rather than recreating a large dataset? 2) I wonder if there are cases where reversing the condition in Select does not do the job... $\endgroup$ – Rho Phi Oct 26 '15 at 23:36
  • 1
    $\begingroup$ Well, an expression test is an expression test, negated or not. It will have to go through each row to return its results. $\endgroup$ – J. M. will be back soon Oct 26 '15 at 23:38
  • $\begingroup$ I do not have a large thing to test this on, but sounds like one of these Mathematica performance things, like Table performs very differently from Map ... $\endgroup$ – Rho Phi Oct 26 '15 at 23:43
2
$\begingroup$

Here's one way, not necessarily the most efficient:

MyDataSet[Select[#point[Fsr] == 1 & /* Not]]

$\endgroup$
  • $\begingroup$ That's just composing Not[] and the equality test, no? Why not use Unequal[] to begin with? $\endgroup$ – J. M. will be back soon Oct 28 '15 at 18:17
  • $\begingroup$ @J.M., correct, the advantange of this composition over Unequal is it turns Select into delete independent of the matching logic, eg if the user replaced == by <. $\endgroup$ – alancalvitti Oct 28 '15 at 18:36
0
$\begingroup$

There is a workaround if you use the named row style of Dataset (an association of associations) but don't actually apply Dataset to it. You can still perform querying as you can with a dataset but will have to explicitly use Query instead of it being implicitly used in the dataset[...] format.

assco = Association @@ 
 MapIndexed[First@#2 -> #1 &]@
   {<|"a" -> 5, "b" -> 2|>, <|"a" -> 3, "b" -> 2|>, <|"a" -> 5, "b" -> -1|>};

Here I have just indexed them with row number but you can use any expression. Now KeyDropFrom can be used with Select to drop the rows you are not interested in without making a new copy of the data. Below the rows with "a"-> 5 are dropped; the first and last row.

KeyDropFrom[assco, Keys@Select[#a == 5 &][assco]];
assco
(* <|2 -> <|"a" -> 3, "b" -> 2|>|> *)

The second row remains in assco with the others dropped.

Hope this helps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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