Ive been thinking about what is the best way to solve this, any advise?
The table/matrix X is:
X <- read.table(text = " a b c d e
0 27 0 28 8
1 14 24 32 33
0 4 22 25 27
0 3 7 26 34
0 28 33 31 21
0 16 17 24 18
1 3 19 0 12
0 2 23 5 24
2 17 22 22 10
0 35 15 17 2",
header = TRUE, stringsAsFactors = FALSE)
or using matlab:
X =[
0 27 0 28 8
1 14 24 32 33
0 4 22 25 27
0 3 7 26 34
0 28 33 31 21
0 16 17 24 18
1 3 19 0 12
0 2 23 5 24
2 17 22 22 10
0 35 15 17 2];
How could I obtain a table/matrix A and B which contains:
rows and columns accumulated each 5 values until the maximum value of table X -> in this case: 0-5;0-10;0-15;0-20.. 0-35 (for both rows and columns).
Table A:
The first thing is to select only the positive values of a, and then count the number of times these conditions occur:
The entry (1,1) of the table/matrix A would be the number of times the b values are among 0-5 and d values are among 0-5. The entry (2,1) would be the number of times the b values are among 0-5 and d values are among 0-10. The entry (3,1) would be the number of times the b values are among 0-5 and d values are among 0-15... this until the row is 0-35.
The entry (1,2) of the table/matrix A would be the number of times the b values are among 0-10 and d values are among 0-5. The entry (2,2) would be the number of times the b values are among 0-10 and d values are among 0-10. The entry (3,2) would be the number of times the b values are among 0-10 and d values are among 0-15... this until the row is 0-35.
We form a 7x7 table/matrix, the results show this:
A:
0-5 0-10 0-15 0-20 0-25 0-30 0-35
0-5 1 1 1 1 1 1 1
0-10 1 1 1 1 1 1 1
0-15 1 1 1 1 1 1 1
0-20 1 1 1 1 1 1 1
0-25 1 1 1 2 2 2 2
0-30 1 1 1 2 2 2 2
0-35 1 1 2 3 3 3 3
Where the columns are the intervals of b values and the rows the intervals for d values
The meaning of the table/matrix A is the number of times the a values are higher than 0 and match different combinations intervals (each 5 values) among column b and d. For example, for the entry (1,1) of result table A is 1 because in the row 7 of table X, there is only 1 number which a>0, b=3 (among 0-5) and d=0 (among 0-5). Other example is the entry (7,4), which is 3 since there three times: a>0, b is among 0-20 and d is among 0-35
The table/matrix B, would be the same table A but comparing columns c and e. B is:
B:
0-5 0-10 0-15 0-20 0-25 0-30 0-35
0-5 1 1 1 1 1 1 1
0-10 2 2 2 2 2 2 2
0-15 2 2 2 2 2 2 2
0-20 2 2 2 2 2 2 3
0-25 2 2 2 4 4 4 5
0-30 4 4 4 6 6 7 8
0-35 4 4 5 7 7 9 10
See Question&Answers more detail:os