want to remove individual points or chunks of data
Interpreting individual points as an elements of input data, and chunks as positions in input data:
ClearAll[complementF]
complementF[lst_, pos_, el_: {}] := Module[{pf = Composition[Union, Flatten, Query @ pos],
r = Range @ Length @ lst}, DeleteCases[lst[[Complement[r, pf @ r]]], Alternatives @@ el]]
where pos
is the list of positions and the optional last argument el
is the list of elements to be removed from lst
.
Examples:
complementF[Range[10], {{5}, 7 ;; 9, 6 ;; 8}]
{1, 2, 3, 4, 10}
complementF[Range[10], {{5}, 7 ;; 9, 6 ;; 8}, {2}]
{1, 3, 4, 10}
complementF[Range[10], {;;2, 2 ;; 6 ;; 2, -2;;}]
{3, 5, 7, 8}
complementF[CharacterRange["A", "K"], {{5}, 7 ;; 9, 6 ;; 8}]
{"A", "B", "C", "D", "J", "K"}
complementF[CharacterRange["A", "K"], {{5}, 7 ;; 9, 6 ;; 8}, {"C", "B"}]
{"A", "D", "J", "K"}
Delete
? $\endgroup$