I have a code like below that contains two loops. The code reads monthly streamflow data and makes it as multi-replicate. The loops are so slow. I was wondering if there is any alternative way to make it faster?
library(xlsx)
library(data.table)
a <- read.xlsx("streamflow.xlsx",sheetName = "Sheet1", header = TRUE)
b=matrix(nrow=129792,ncol=17)
b= data.frame(b)
i=0
for (j in -11:1236)
{
for (k in 1:104)
{
i=i+1
j=j+12
j[j > 1248] <-j-1248
b[i,] <-a[j,]
}
}
Thanks