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
Ettin 0 1 0 0 0 1 0
Gerard 1 0 1 0 1 0 0
Marcus 0 1 0 0 0 1 0
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
mas_max[j,i-1] <- 0
}
}
, , .