To fix the issue you can do I have a large vector which I would like to multiply with a matrix. This is easy to do in r. The issue here is that I would like to define certain blocks of elements within the vector to zero, multiply this with the matrix which then creates a vector, and then repeat for the next block of elements leaving the first block with the original values. , First, I define my vector and matrix.

```
# Data definitions
a <- c(1:6)
b <- matrix(1:36, nrow = 6, ncol = 6)
```

```
# Define blocks of zeroes in vector
define_block <- function(v, n = 2){
# Check that v is a multiple of n
if(length(v)%%n)warning("Vector not a multiple of block length")
# Define blocks of zeroes
lapply(1:(length(v)/n), function(x)replace(v, ((x-1)*n + 1):(x*n), 0))
}
```

```
# Create lists of blocks
block_list <- define_block(a)
```

```
# [[1]]
# [1] 0 0 3 4 5 6
#
# [[2]]
# [1] 1 2 0 0 5 6
#
# [[3]]
# [1] 1 2 3 4 0 0
```

```
# Run through block list and bind result into a matrix
do.call(rbind, lapply(block_list, function(x)x%*%b))
# [,1] [,2] [,3] [,4] [,5] [,6]
#[1,] 86 194 302 410 518 626
#[2,] 66 150 234 318 402 486
#[3,] 30 90 150 210 270 330
```