I would like to count every time a value is in a given range in a matrix row, and then sum these logical results to get a “measure of consistency” for each row.
Playable example:
m1 <- matrix(c(1,2,1,6,3,7,4,2,6,8,11,15), ncol=4, byrow = TRUE)
Above, I indicated the expected result, in the case when each value is within the +/- 1 range of any other values inside this line.
In the first line of m1 first value (1) is within +/- 1 of any other value in this line, therefore, it is TRUE , etc.
In contrast, none of the values in line 4 of m1 are within the same sign from each other, and therefore each is assigned FALSE .
Any pointers would be much appreciated?
Update:
Thanks to the help provided, I can now calculate unique pairs of values that meet the ceiling criteria for any arbitrarily large matrix (using the binomial coefficient, k extracts from n without replacement).
