The issue relates to the requirement when you are using %*% to have conformable matrices.
your code with some printouts in the loop
s = 19
d = 5
ri <- c(2.69801,
5.277278,
13.16717,
33.01168,
79.58261,
223.3391,
559.743,
1498.311,
4139.246,
10488.76,
26430.39,
69133.09,
177503.3,
499546.2,
1401621,
3965602,
10381580,
26180400,
66542260)
h <- data.frame(
X0 = c(1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L),
X1 = c(0.269103514,0.361100764,
0.09199725,0.504507933,0.235404419,0.143407169,0.508207737,
0.239104223,0.147106973,0.003699804,0.661289053,
0.392185539,0.300188289,0.15678112,0.153081316,0.676751858,
0.407648345,0.315651094,0.172243926,0.168544122,
0.015462805,0.805083066,0.535979552,0.443982302,0.300575133,
0.29687533,0.143794013,0.128331208,0.975287633,
0.706184119,0.614186869,0.4707797,0.467079896,0.31399858,
0.298535774,0.170204567,1.000808918,0.731705404,
0.639708154,0.496300985,0.492601181,0.339519865,0.32405706,
0.195725852,0.025521285,1.019279601,0.750176088,
0.658178838,0.514771669,0.511071865,0.357990549,0.342527743,
0.214196535,0.043991969,0.018470683,1.118829965,
0.849726451,0.757729201,0.614322032,0.610622228,0.457540912,
0.442078106,0.313746898,0.143542332,0.118021047,
0.099550363,1.176780881,0.907677367,0.815680117,0.672272948,
0.668573144,0.515491828,0.500029022,0.371697814,
0.201493248,0.175971963,0.157501279,0.057950916,1.380698696,
1.111595182,1.019597932,0.876190763,0.872490959,
0.719409643,0.703946838,0.57561563,0.405411063,0.379889778,
0.361419095,0.261868731,0.203917815,1.55411007,
1.285006556,1.193009306,1.049602137,1.045902333,0.892821017,
0.877358212,0.749027004,0.578822437,0.553301152,
0.534830469,0.435280106,0.377329189,0.173411374,1.733919141,
1.464815627,1.372818377,1.229411208,1.225711404,
1.072630088,1.057167282,0.928836074,0.758631508,
0.733110223,0.714639539,0.615089176,0.55713826,0.353220445,
0.179809071,1.810203793,1.541100279,1.449103029,1.30569586,
1.301996056,1.14891474,1.133451935,1.005120727,
0.83491616,0.809394875,0.790924191,0.691373828,0.633422912,
0.429505097,0.256093723,0.076284652,1.828251563,
1.559148049,1.467150799,1.32374363,1.320043827,1.16696251,
1.151499705,1.023168497,0.852963931,0.827442645,
0.808971962,0.709421599,0.651470683,0.447552867,0.274141493,
0.094332423,0.01804777,1.867071803,1.59796829,
1.505971039,1.362563871,1.358864067,1.20578275,1.190319945,
1.061988737,0.891784171,0.866262885,0.847792202,
0.748241839,0.690290923,0.486373107,0.312961733,0.133152663,
0.05686801,0.03882024),
X2 = c(0.0724,0.13,0.00846,0.255,
0.0554,0.0206,0.258,0.0572,0.0216,1.37e-05,0.437,0.154,
0.0901,0.0246,0.0234,0.458,0.166,0.0996,0.0297,
0.0284,0.000239,0.648,0.287,0.197,0.0903,0.0881,
0.0207,0.0165,0.951,0.499,0.377,0.222,0.218,0.0986,
0.0891,0.029,1,0.535,0.409,0.246,0.243,0.115,0.105,
0.0383,0.000651,1.04,0.563,0.433,0.265,0.261,0.128,
0.117,0.0459,0.00194,0.000341,1.25,0.722,0.574,0.377,
0.373,0.209,0.195,0.0984,0.0206,0.0139,0.00991,
1.38,0.824,0.665,0.452,0.447,0.266,0.25,0.138,0.0406,
0.031,0.0248,0.00336,1.91,1.24,1.04,0.768,0.761,
0.518,0.496,0.331,0.164,0.144,0.131,0.0686,0.0416,
2.42,1.65,1.42,1.1,1.09,0.797,0.77,0.561,0.335,
0.306,0.286,0.189,0.142,0.0301,3.01,2.15,1.88,1.51,
1.5,1.15,1.12,0.863,0.576,0.537,0.511,0.378,0.31,
0.125,0.0323,3.28,2.37,2.1,1.7,1.7,1.32,1.28,1.01,
0.697,0.655,0.626,0.478,0.401,0.184,0.0656,
0.00582,3.34,2.43,2.15,1.75,1.74,1.36,1.33,1.05,0.728,
0.685,0.654,0.503,0.424,0.2,0.0752,0.0089,0.000326,
3.49,2.55,2.27,1.86,1.85,1.45,1.42,1.13,0.795,
0.75,0.719,0.56,0.477,0.237,0.0979,0.0177,0.00323,
0.00151),
X3 = c(0.0195,0.0471,0.000779,0.128,
0.013,0.00295,0.131,0.0137,0.00318,5.06e-08,0.289,
0.0603,0.0271,0.00385,0.00359,0.31,0.0677,0.0315,
0.00511,0.00479,3.7e-06,0.522,0.154,0.0875,0.0272,
0.0262,0.00297,0.00211,0.928,0.352,0.232,0.104,0.102,
0.031,0.0266,0.00493,1,0.392,0.262,0.122,0.12,
0.0391,0.034,0.0075,1.66e-05,1.06,0.422,0.285,0.136,
0.133,0.0459,0.0402,0.00983,8.51e-05,6.3e-06,1.4,0.614,
0.435,0.232,0.228,0.0958,0.0864,0.0309,0.00296,
0.00164,0.000987,1.63,0.748,0.543,0.304,0.299,0.137,
0.125,0.0514,0.00818,0.00545,0.00391,0.000195,2.63,
1.37,1.06,0.673,0.664,0.372,0.349,0.191,0.0666,
0.0548,0.0472,0.018,0.00848,3.75,2.12,1.7,1.16,1.14,
0.712,0.675,0.42,0.194,0.169,0.153,0.0825,0.0537,
0.00521,5.21,3.14,2.59,1.86,1.84,1.23,1.18,0.801,
0.437,0.394,0.365,0.233,0.173,0.0441,0.00581,5.93,
3.66,3.04,2.23,2.21,1.52,1.46,1.02,0.582,0.53,
0.495,0.33,0.254,0.0792,0.0168,0.000444,6.11,3.79,3.16,
2.32,2.3,1.59,1.53,1.07,0.621,0.567,0.529,0.357,
0.276,0.0896,0.0206,0.000839,5.88e-06,6.51,4.08,
3.42,2.53,2.51,1.75,1.69,1.2,0.709,0.65,0.609,0.419,
0.329,0.115,0.0307,0.00236,0.000184,5.85e-05),
X4 = c(0.00524,0.017,7.16e-05,0.0648,
0.00307,0.000423,0.0667,0.00327,0.000468,1.87e-10,
0.191,0.0237,0.00812,0.000604,0.000549,0.21,0.0276,
0.00993,0.00088,0.000807,5.72e-08,0.42,0.0825,0.0389,
0.00816,0.00777,0.000428,0.000271,0.905,0.249,0.142,
0.0491,0.0476,0.00972,0.00794,0.000839,1,0.287,
0.167,0.0607,0.0589,0.0133,0.011,0.00147,4.24e-07,
1.08,0.317,0.188,0.0702,0.0682,0.0164,0.0138,0.0021,
3.75e-06,1.16e-07,1.57,0.521,0.33,0.142,0.139,0.0438,
0.0382,0.00969,0.000425,0.000194,9.82e-05,1.92,
0.679,0.443,0.204,0.2,0.0706,0.0625,0.0191,0.00165,
0.000959,0.000615,1.13e-05,3.63,1.53,1.08,0.589,0.579,
0.268,0.246,0.11,0.027,0.0208,0.0171,0.0047,
0.00173,5.83,2.73,2.03,1.21,1.2,0.635,0.593,0.315,
0.112,0.0937,0.0818,0.0359,0.0203,0.000904,9.04,4.6,
3.55,2.28,2.26,1.32,1.25,0.744,0.331,0.289,0.261,
0.143,0.0964,0.0156,0.00105,10.7,5.64,4.41,2.91,2.87,
1.74,1.65,1.02,0.486,0.429,0.391,0.228,0.161,
0.034,0.0043,3.39e-05,11.2,5.91,4.63,3.07,3.04,1.85,
1.76,1.1,0.529,0.469,0.428,0.253,0.18,0.0401,
0.00565,7.92e-05,1.06e-07,12.2,6.52,5.14,3.45,3.41,2.11,
2.01,1.27,0.632,0.563,0.517,0.313,0.227,0.056,
0.00959,0.000314,1.05e-05,2.27e-06)
) |> as.matrix()
Gi <- matrix(0,s,d)
index = 1
for (j in 2:s) {
cat("dim(as.matrix(ri[1:j-1]))",dim(as.matrix(ri[1:j-1])),"\n")
cat("dim(as.matrix(h[index:index+j-2,]))",dim(as.matrix(h[index:index+j-2,])),"\n")
Gi[j,]= Gi[j,]+as.matrix(ri[1:j-1]) %*% as.matrix(h[index:index+j-2,])
index = index + j-1
}
dim(as.matrix(ri[1:j-1])) 1 1
dim(as.matrix(h[index:index+j-2,])) 5 1
Error in as.matrix(ri[1:j - 1]) %*% as.matrix(h[index:index + j - 2, ]) :
non-conformable arguments
I think what to do depends on what the intended mathematical operation is; which without context is not possible.