2
Considering the following date.frames:
library(zoo)
A<-data.frame(x1=(0:9),x2=rep(0:1,5),x3=rep(0:4,2))
B<-apply(A, 2, function(x) rollapply(x, width = 2, FUN = sum, fill = NA, align = 'r', na.rm=TRUE))
C<-apply(A, 2, function(x) rollapply(x, width = 3, FUN = sum, fill = NA, align = 'r', na.rm=TRUE))
D<-apply(A, 2, function(x) rollapply(x, width = 4, FUN = sum, fill = NA, align = 'r', na.rm=TRUE))
Where B, C and D are the result of the accumulation of A values, carried out using the mobile window function rollapply
, ranging from one in one of 2 to 4.
I want to test when A, B, C and D are equal, that is, A==B, A==B==C and A==B=C==D. After this, the test result should be converted into notes, for example:
Teste | Nota
"A==B" | 1
"A==B==C" | 20
"A==B==C==D"| 300
Storing each note in a date.frame at its respective position, as for "A==B":
x1 x2 x3
[1,] NA NA NA
[2,] 1 1 1
[3,] 0 0 0
[4,] 0 1 0
[5,] 0 0 0
[6,] 0 1 0
[7,] 0 0 1
[8,] 0 1 0
[9,] 0 0 0
[10,] 0 1 0
After the generation of each note (data.frame), I need to know the maximum grade for each cell. How to perform this procedure?
@ It worked! I’m trying to generalize to cases with more matrices. As soon as I can I’ll upload the true data.
– Jean