Given the following data.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))
Since B, C and D are the result of the accumulation of values of A, performed with the use of the window function rollapply
, varying from one to one of 2 to 4.
I want to test when A, B, C, and D are the same, that is, A == B, A == B == C and A == B == C == D. After this, the test results should be converted into notes, for example:
Teste | Nota
"A==B" | 1
"A==B==C" | 20
"A==B==C==D"| 300
By storing each note in a data.frame in 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 do I do this?