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?
2 Answers
Here's one way, not necessarily the most efficient:
MyDataSet[Select[#point[Fsr] == 1 & /* Not]]
-
$\begingroup$ That's just composing
Not[]
and the equality test, no? Why not useUnequal[]
to begin with? $\endgroup$ Oct 28, 2015 at 18:17 -
$\begingroup$ @J.M., correct, the advantange of this composition over
Unequal
is it turnsSelect
into delete independent of the matching logic, eg if the user replaced==
by<
. $\endgroup$ Oct 28, 2015 at 18:36
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.
MyDataSet[Select[#point[Fsr] != 1 &]]
do? $\endgroup$Select
does not do the job... $\endgroup$