Search for "local maxims" but ignore a value less than 20% of the highest

I am trying to create a function to find the "local maxima" in each row of my data, but ignore it if they do not have at least 20% of the maximum number in the row.

The function I use to find local maxims:

which(diff(sign(diff(Gene name)))==-2)+1

but I would like to change it and make a choice only if the other highs are at least 20% of the highest value.

What is my data:

Name     Mo   Tue   Wen   Thu   Fr   Sat   Sun   
Mark     0     32    53    11    0    33    52   
Ettin    22    51    31    0     0    1      0
Gerard   36    0     13    0    111   33     0   
Marcus   0     44    31    10    0    2      0     

What I got with my function:

Name     Mo   Tue   Wen   Thu   Fr   Sat   Sun   
Mark     0     0     1     0     0    0     1   ## Two local maximas
Ettin    0     1     0     0     0    1     0   ## Two local maximas (Should be one!)
Gerard   1     0     1     0     1    0     0   ## Three local maximas (Should be two!)
Marcus   0     1     0     0     0    1     0   ## Two local maximas (Should be one!)

For 3 lines, the output is incorrect, because the values ​​in the cells (Ettin, Sat) and (Gerard, Wen) and (Marcus, Sat) are not even close to 20% of the highest value.

What I expect to get with a new function:

Name     Mo   Tue   Wen   Thu   Fr   Sat   Sun   
Mark     0     0     1     0     0    0     1   
Ettin    0     1     0     0     0    0     0   
Gerard   1     0     0     0     1    0     0   
Marcus   0     1     0     0     0    0     0  

Is it possible to write such a function?

    if(master[j,i]>master[j,i-1]) {
      if(master[j,i] > 0.2*max(master [j,])) {
        mas_max[j,i] <- 1 ## Setting maxima
        mas_max[j,i-1] <- 0 ## Removing potential maxima before
 }
}

, , .

+4
1

ind <- which(diff(sign(diff(GeneName)))==-2)+1

, 20%

ind[GeneName[ind] >= 0.2 * max(GeneName[ind])]

, ==-2 , , , c (0,10,10,0) - , , .

+5

Source: https://habr.com/ru/post/1535525/


All Articles