number of items to replace is not a multiple of replacement length1111

Hi guys , I just wrote the following code

Gi <- matrix(0,s,d)
index = 1
for (j in 2:s) {
  Gi[j,]= Gi[j,]+as.matrix(ri[1:j-1]) %*% as.matrix(h[index:index+j-2,])
  index = index + j-1
}

However,it always makes the following error

Error in Gi[j, ] <- Gi[j, ] + as.matrix(ri[1:j - 1]) %*% as.matrix(h[index:index +  : 
  number of items to replace is not a multiple of replacement length

Any help will be deeply appreciated. Thanks in advance!

Does this evaluate to 0 at any point?

Thanks for providing code. Could you kindly take further steps to make it easier for other forum users to help you? Share some representative data that will enable your code to run and show the problematic behaviour.

How do I share data for a reprex?

You might use tools such as the library datapasta, or the base function dput() to share a portion of data in code form, i.e. that can be copied from forum and pasted to R session.

Reprex Guide

1 Like

Thanks for your reply . I check it again,it doesn't evaluate at 0

Okay. I will post my data.Thanks

s = 19
d = 5
> ri
           [,1]
1  2.698010e+00
2  5.277278e+00
3  1.316717e+01
4  3.301168e+01
5  7.958261e+01
6  2.233391e+02
7  5.597430e+02
8  1.498311e+03
9  4.139246e+03
10 1.048876e+04
11 2.643039e+04
12 6.913309e+04
13 1.775033e+05
14 4.995462e+05
15 1.401621e+06
16 3.965602e+06
17 1.038158e+07
18 2.618040e+07
19 6.654226e+07
> h
    X0          X1           X2           X3           X4
1    1 0.269103514 7.241670e-02 1.948759e-02 5.244179e-03
2    1 0.361100764 1.303938e-01 4.708529e-02 1.700253e-02
3    1 0.091997250 8.463494e-03 7.786182e-04 7.163073e-05
4    1 0.504507933 2.545283e-01 1.284115e-01 6.478463e-02
5    1 0.235404419 5.541524e-02 1.304499e-02 3.070849e-03
6    1 0.143407169 2.056562e-02 2.949257e-03 4.229446e-04
7    1 0.508207737 2.582751e-01 1.312574e-01 6.670603e-02
8    1 0.239104223 5.717083e-02 1.366979e-02 3.268504e-03
9    1 0.147106973 2.164046e-02 3.183463e-03 4.683096e-04
10   1 0.003699804 1.368855e-05 5.064495e-08 1.873764e-10
11   1 0.661289053 4.373032e-01 2.891838e-01 1.912341e-01
12   1 0.392185539 1.538095e-01 6.032186e-02 2.365736e-02
13   1 0.300188289 9.011301e-02 2.705087e-02 8.120354e-03
14   1 0.156781120 2.458032e-02 3.853730e-03 6.041921e-04
15   1 0.153081316 2.343389e-02 3.587291e-03 5.491472e-04
16   1 0.676751858 4.579931e-01 3.099477e-01 2.097577e-01
17   1 0.407648345 1.661772e-01 6.774185e-02 2.761485e-02
18   1 0.315651094 9.963561e-02 3.145009e-02 9.927255e-03
19   1 0.172243926 2.966797e-02 5.110128e-03 8.801884e-04
20   1 0.168544122 2.840712e-02 4.787853e-03 8.069645e-04
21   1 0.015462805 2.390984e-04 3.697131e-06 5.716802e-08
22   1 0.805083066 6.481587e-01 5.218216e-01 4.201098e-01
23   1 0.535979552 2.872741e-01 1.539730e-01 8.252640e-02
24   1 0.443982302 1.971203e-01 8.751792e-02 3.885641e-02
25   1 0.300575133 9.034541e-02 2.715558e-02 8.162293e-03
26   1 0.296875330 8.813496e-02 2.616510e-02 7.767771e-03
27   1 0.143794013 2.067672e-02 2.973188e-03 4.275267e-04
28   1 0.128331208 1.646890e-02 2.113474e-03 2.712246e-04
29   1 0.975287633 9.511860e-01 9.276799e-01 9.047547e-01
30   1 0.706184119 4.986960e-01 3.521712e-01 2.486977e-01
31   1 0.614186869 3.772255e-01 2.316870e-01 1.422991e-01
32   1 0.470779700 2.216335e-01 1.043406e-01 4.912142e-02
33   1 0.467079896 2.181636e-01 1.018998e-01 4.759537e-02
34   1 0.313998580 9.859511e-02 3.095872e-02 9.720995e-03
35   1 0.298535774 8.912361e-02 2.660659e-02 7.943018e-03
36   1 0.170204567 2.896959e-02 4.930757e-03 8.392374e-04
37   1 1.000808918 1.001618e+00 1.002429e+00 1.003240e+00
38   1 0.731705404 5.353928e-01 3.917498e-01 2.866454e-01
39   1 0.639708154 4.092265e-01 2.617855e-01 1.674663e-01
40   1 0.496300985 2.463147e-01 1.222462e-01 6.067092e-02
41   1 0.492601181 2.426559e-01 1.195326e-01 5.888190e-02
42   1 0.339519865 1.152737e-01 3.913772e-02 1.328803e-02
43   1 0.324057060 1.050130e-01 3.403020e-02 1.102773e-02
44   1 0.195725852 3.830861e-02 7.497985e-03 1.467550e-03
45   1 0.025521285 6.513360e-04 1.662293e-05 4.242386e-07
46   1 1.019279601 1.038931e+00 1.058961e+00 1.079377e+00
47   1 0.750176088 5.627642e-01 4.221722e-01 3.167035e-01
48   1 0.658178838 4.331994e-01 2.851227e-01 1.876617e-01
49   1 0.514771669 2.649899e-01 1.364093e-01 7.021963e-02
50   1 0.511071865 2.611945e-01 1.334891e-01 6.822254e-02
51   1 0.357990549 1.281572e-01 4.587908e-02 1.642428e-02
52   1 0.342527743 1.173253e-01 4.018715e-02 1.376522e-02
53   1 0.214196535 4.588016e-02 9.827370e-03 2.104989e-03
54   1 0.043991969 1.935293e-03 8.513736e-05 3.745360e-06
55   1 0.018470683 3.411661e-04 6.301572e-06 1.163943e-07
56   1 1.118829965 1.251780e+00 1.400530e+00 1.566954e+00
57   1 0.849726451 7.220350e-01 6.135323e-01 5.213346e-01
58   1 0.757729201 5.741535e-01 4.350529e-01 3.296523e-01
59   1 0.614322032 3.773916e-01 2.318399e-01 1.424244e-01
60   1 0.610622228 3.728595e-01 2.276763e-01 1.390242e-01
61   1 0.457540912 2.093437e-01 9.578330e-02 4.382478e-02
62   1 0.442078106 1.954331e-01 8.639667e-02 3.819408e-02
63   1 0.313746898 9.843712e-02 3.088434e-02 9.689866e-03
64   1 0.143542332 2.060440e-02 2.957604e-03 4.245413e-04
65   1 0.118021047 1.392897e-02 1.643911e-03 1.940161e-04
66   1 0.099550363 9.910275e-03 9.865715e-04 9.821355e-05
67   1 1.176780881 1.384813e+00 1.629622e+00 1.917708e+00
68   1 0.907677367 8.238782e-01 7.478156e-01 6.787753e-01
69   1 0.815680117 6.653341e-01 5.426998e-01 4.426694e-01
70   1 0.672272948 4.519509e-01 3.038344e-01 2.042596e-01
71   1 0.668573144 4.469900e-01 2.988455e-01 1.998001e-01
72   1 0.515491828 2.657318e-01 1.369826e-01 7.061340e-02
73   1 0.500029022 2.500290e-01 1.250218e-01 6.251451e-02
74   1 0.371697814 1.381593e-01 5.135350e-02 1.908798e-02
75   1 0.201493248 4.059953e-02 8.180531e-03 1.648322e-03
76   1 0.175971963 3.096613e-02 5.449171e-03 9.589013e-04
77   1 0.157501279 2.480665e-02 3.907080e-03 6.153700e-04
78   1 0.057950916 3.358309e-03 1.946171e-04 1.127824e-05
79   1 1.380698696 1.906329e+00 2.632066e+00 3.634090e+00
80   1 1.111595182 1.235644e+00 1.373536e+00 1.526816e+00
81   1 1.019597932 1.039580e+00 1.059954e+00 1.080726e+00
82   1 0.876190763 7.677103e-01 6.726606e-01 5.893790e-01
83   1 0.872490959 7.612405e-01 6.641754e-01 5.794871e-01
84   1 0.719409643 5.175502e-01 3.723306e-01 2.678582e-01
85   1 0.703946838 4.955412e-01 3.488346e-01 2.455610e-01
86   1 0.575615630 3.313334e-01 1.907207e-01 1.097818e-01
87   1 0.405411063 1.643581e-01 6.663260e-02 2.701359e-02
88   1 0.379889778 1.443162e-01 5.482427e-02 2.082718e-02
89   1 0.361419095 1.306238e-01 4.720992e-02 1.706257e-02
90   1 0.261868731 6.857523e-02 1.795771e-02 4.702563e-03
91   1 0.203917815 4.158248e-02 8.479408e-03 1.729102e-03
92   1 1.554110070 2.415258e+00 3.753577e+00 5.833472e+00
93   1 1.285006556 1.651242e+00 2.121857e+00 2.726600e+00
94   1 1.193009306 1.423271e+00 1.697976e+00 2.025701e+00
95   1 1.049602137 1.101665e+00 1.156310e+00 1.213665e+00
96   1 1.045902333 1.093912e+00 1.144125e+00 1.196643e+00
97   1 0.892821017 7.971294e-01 7.116939e-01 6.354152e-01
98   1 0.877358212 7.697574e-01 6.753530e-01 5.925265e-01
99   1 0.749027004 5.610415e-01 4.202352e-01 3.147675e-01
100  1 0.578822437 3.350354e-01 1.939260e-01 1.122487e-01
101  1 0.553301152 3.061422e-01 1.693888e-01 9.372303e-02
102  1 0.534830469 2.860436e-01 1.529848e-01 8.182096e-02
103  1 0.435280106 1.894688e-01 8.247199e-02 3.589841e-02
104  1 0.377329189 1.423773e-01 5.372312e-02 2.027130e-02
105  1 0.173411374 3.007150e-02 5.214741e-03 9.042954e-04
106  1 1.733919141 3.006476e+00 5.212986e+00 9.038895e+00
107  1 1.464815627 2.145685e+00 3.143033e+00 4.603963e+00
108  1 1.372818377 1.884630e+00 2.587255e+00 3.551831e+00
109  1 1.229411208 1.511452e+00 1.858196e+00 2.284487e+00
110  1 1.225711404 1.502368e+00 1.841470e+00 2.257111e+00
111  1 1.072630088 1.150535e+00 1.234099e+00 1.323731e+00
112  1 1.057167282 1.117603e+00 1.181493e+00 1.249036e+00
113  1 0.928836074 8.627365e-01 8.013407e-01 7.443142e-01
114  1 0.758631508 5.755218e-01 4.366089e-01 3.312253e-01
115  1 0.733110223 5.374506e-01 3.940105e-01 2.888531e-01
116  1 0.714639539 5.107097e-01 3.649733e-01 2.608244e-01
117  1 0.615089176 3.783347e-01 2.327096e-01 1.431371e-01
118  1 0.557138260 3.104030e-01 1.729374e-01 9.635005e-02
119  1 0.353220445 1.247647e-01 4.406944e-02 1.556623e-02
120  1 0.179809071 3.233130e-02 5.813461e-03 1.045313e-03
121  1 1.810203793 3.276838e+00 5.931744e+00 1.073767e+01
122  1 1.541100279 2.374990e+00 3.660098e+00 5.640578e+00
123  1 1.449103029 2.099900e+00 3.042971e+00 4.409578e+00
124  1 1.305695860 1.704842e+00 2.226005e+00 2.906485e+00
125  1 1.301996056 1.695194e+00 2.207136e+00 2.873682e+00
126  1 1.148914740 1.320005e+00 1.516573e+00 1.742413e+00
127  1 1.133451935 1.284713e+00 1.456161e+00 1.650488e+00
128  1 1.005120727 1.010268e+00 1.015441e+00 1.020641e+00
129  1 0.834916160 6.970850e-01 5.820075e-01 4.859275e-01
130  1 0.809394875 6.551201e-01 5.302508e-01 4.291823e-01
131  1 0.790924191 6.255611e-01 4.947714e-01 3.913267e-01
132  1 0.691373828 4.779978e-01 3.304751e-01 2.284819e-01
133  1 0.633422912 4.012246e-01 2.541448e-01 1.609812e-01
134  1 0.429505097 1.844746e-01 7.923279e-02 3.403089e-02
135  1 0.256093723 6.558399e-02 1.679565e-02 4.301260e-03
136  1 0.076284652 5.819348e-03 4.439270e-04 3.386481e-05
137  1 1.828251563 3.342504e+00 6.110938e+00 1.117233e+01
138  1 1.559148049 2.430943e+00 3.790199e+00 5.909482e+00
139  1 1.467150799 2.152531e+00 3.158088e+00 4.633392e+00
140  1 1.323743630 1.752297e+00 2.319592e+00 3.070545e+00
141  1 1.320043827 1.742516e+00 2.300197e+00 3.036361e+00
142  1 1.166962510 1.361802e+00 1.589171e+00 1.854503e+00
143  1 1.151499705 1.325952e+00 1.526833e+00 1.758148e+00
144  1 1.023168497 1.046874e+00 1.071128e+00 1.095945e+00
145  1 0.852963931 7.275475e-01 6.205717e-01 5.293253e-01
146  1 0.827442645 6.846613e-01 5.665180e-01 4.687611e-01
147  1 0.808971962 6.544356e-01 5.294201e-01 4.282860e-01
148  1 0.709421599 5.032790e-01 3.570370e-01 2.532898e-01
149  1 0.651470683 4.244141e-01 2.764933e-01 1.801273e-01
150  1 0.447552867 2.003036e-01 8.964644e-02 4.012152e-02
151  1 0.274141493 7.515356e-02 2.060271e-02 5.648057e-03
152  1 0.094332423 8.898606e-03 8.394271e-04 7.918519e-05
153  1 0.018047770 3.257220e-04 5.878556e-06 1.060948e-07
154  1 1.867071803 3.485957e+00 6.508532e+00 1.215190e+01
155  1 1.597968290 2.553503e+00 4.080416e+00 6.520376e+00
156  1 1.505971039 2.267949e+00 3.415465e+00 5.143592e+00
157  1 1.362563871 1.856580e+00 2.529709e+00 3.446890e+00
158  1 1.358864067 1.846512e+00 2.509158e+00 3.409605e+00
159  1 1.205782750 1.453912e+00 1.753102e+00 2.113860e+00
160  1 1.190319945 1.416862e+00 1.686519e+00 2.007497e+00
161  1 1.061988737 1.127820e+00 1.197732e+00 1.271978e+00
162  1 0.891784171 7.952790e-01 7.092172e-01 6.324687e-01
163  1 0.866262885 7.504114e-01 6.500535e-01 5.631172e-01
164  1 0.847792202 7.187516e-01 6.093520e-01 5.166039e-01
165  1 0.748241839 5.598658e-01 4.189151e-01 3.134498e-01
166  1 0.690290923 4.765016e-01 3.289247e-01 2.270537e-01
167  1 0.486373107 2.365588e-01 1.150558e-01 5.596007e-02
168  1 0.312961733 9.794505e-02 3.065305e-02 9.593232e-03
169  1 0.133152663 1.772963e-02 2.360748e-03 3.143398e-04
170  1 0.056868010 3.233971e-03 1.839095e-04 1.045857e-05
171  1 0.038820240 1.507011e-03 5.850253e-05 2.271082e-06

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.