I'm trying to apply filters to a large matrix. The matrix "logcounts1" consists of 8978 rows and 4 columns.
The filter should be applied per row, so I could then select those rows in which at least one value is out of the interval. The filter makes use of an interval consisting on the mean of each row as a central value + - the standard deviation. Average and SD of each row is respectively comprised in vectors "Average1" and "SDr1".
I also defined matrices "alpha" for rows in which at least one column value is out of the range of the interval and "beta" to store rows whose values keep in the interval at all times.
for (i in 1:8978) {
if (logcounts1[i,1] > average1 [i]+SDr1[i] | logcounts1[i,2] > average1 [i]+SDr1[i] | logcounts1[i,3] > average1 [i]+SDr1[i] | logcounts1[i,4] > average1 [i]+SDr1[i] | logcounts1[i,1] < average1 [i]+SDr1[i] | logcounts1[i,2] < average1 [i]+SDr1[i] | logcounts1[i,3] > average1 [i]+SDr1[i] | logcounts1[i,4] > average1 [i]+SDr1[i]) {
alpha <- rbind(alpha,logcounts1[i,])
} else {
beta <- rbind(beta, logcounts1[i,])
}
}
I really hope you can help me out guys, I'm quite new on this. Bests
I made an example on excel <- click here
Basically, red cells are values going of the interval (mean+-StandardDeviation). Then rows 1,2 and 5, which have out-of-range values should be stored in a new matrix "alpha", so the output should then be:
Besides, rows not containing any out-of-range values should also be stored in another matrix ("beta"), of output: