I have two data matrices of the same dimensions, let one matrix is denoted by A and the other is denoted by B having dimension 24*365 where 24 denotes the hours and 365 are the number of days (mean each matrix having hourly data of one year). Suppose I choose a single day, for example, Sunday, suppose it's in the 3rd column of both the matrices. similarly, I choose all the remaining columns of the Sunday from both the matrices so I obtain two submatrices from each matrix A and B of the Sunday. Then I take each submatrix as a vector and I calculate the mean square error and percentage mean square error from these two vectors. Similarly, the same process is repeated for the remaining days of the week. My question is that can any do this whole process using loops, that through loops for each day submatrix is selected from both matrices A and B. Then taking each submatrix as a vector and calculate mean square error and percentage mean square error separately for each day. I try to explain my question manually with an example of taking any two matrices denoted by C and D, but due to the large dimensions of my original data matrices, there are more submatrices which makes it's quite time-consuming when we do this manually.
C <- matrix(16:155, ncol=14, byrow=T)
D<- matrix(50:189,ncol=14, byrow=T)
sub_C1 <- C[,c(1+(0:6)*2)]
sub_D1 <- D[,c(1+(0:6)*2)]
sub_C2 <- C[,c(2+(0:6)*2)]
sub_D2 <- D[,c(2+(0:6)*2)]
sub_C3 <- C[,c(1+(0:4)*3)]
sub_D3 <- D[,c(1+(0:4)*3)]
################mean square error################
mse_1 <- mean(abs(as.vector(sub_C1)-as.vector(sub_D1)))
mse_2 <- mean(abs(as.vector(sub_C2)-as.vector(sub_D2)))
mse_3 <- mean(abs(as.vector(sub_C3)-as.vector(sub_D3)))
################## mean percentage absolute error############
mape_1 <- mean(abs(as.vector(sub_C1)-as.vector(sub_D1))/as.vector(sub_C1))
mape_2 <- mean(abs(as.vector(sub_C2)-as.vector(sub_D2))/as.vector(sub_C2))
mape_3 <- mean(abs(as.vector(sub_C3)-as.vector(sub_D3))/as.vector(sub_C3))
#############################################################
Can someone helps that through loops that the same submatrix is selected from each matrix C and D, and calculate errors from each submatrix separately.