Deleting elements from a list based on their relative position to one another

I have a data set where I often get pairs of spikes that occur randomly but the pair is always separated within $n$ places of each other. I.e. the spacing between the pairs, in index, is always constant.

Is there a way, given some other condition to pick out the first spike (I use something like Select[IndexedData[[1;;,{1,2,3}]], #[[3]] > threshold &])to then remove the $n \pm1$ points after this peak?

• Can you provide a sample of the data to work with? Also, do you know "n" or is that something that you don't know a priori? Jun 7, 2018 at 12:44
• @Fraccalo I know that $n$ is always 41. I will attach a data sample now...
– N.B.
Jun 7, 2018 at 12:56

If I understand the question correctly, you may use something like

data[[Complement[Range@len, n + 1 + peaks]]]


where I'm assuming one-dimensional data for simplicity, len is the size of your dataset and peaks is a list of positions for your peaks.

For example, take

n = 3;
len = 20;
data = RandomInteger[100, len]


giving the following sample data:

{72, 5, 36, 57, 97, 95, 86, 11, 5, 4, 35, 82, 59, 88, 6, 53, 6, 100, 39, 53}


then you find the peak positions with

peaks = Select[Range@len, data[[#]] > 90 &]


giving in this case

{5, 6, 18}


Then the line above results in

{72, 5, 36, 57, 97, 86, 11, 4, 35, 88, 6, 53, 100, 39}


You may want to look at Pick. For example, using Fidel's data for consistency:

n = 3;
len = 20;
data = {72, 5, 36, 57, 97, 95, 86, 11, 5, 4, 35, 82, 59, 88, 6, 53, 6, 100, 39, 53};


{1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1}

Note that here I drop both the detected peaks at positions 5, 6, 18 and also the elements offset by three. If you choose this method reference UnitStep, PadRight, TimesBy.