Good afternoon. I am working in R (in RStudio specifically) and have an error which I have seen in other threads but have been unable to translate the solutions to my own code.
I have quite a lengthy "if" loop (with nested "else" and "for" statements), however the key parts of my code are that the variable BCmth is defined as:
BCmth<- matrix(NA, nrow = 3000000,ncol = 4)
and BCstore as:
BCstore<- matrix(1,1000,2*round(iForeper))
And in this section of the loop they are used as such:
BCmth[,4] <- cumsum(BCmth[,3]) # compute cumulative density booking curve
BCstore[1:size(BCmth[,4],1),m] <- BCmth[,2] # store the month for the booking curve
BCstore[1:size(BCmth[,4],1),m+1] <- BCmth[,4] / BCmth[length(BCmth):4] # store the booking curve value as a %-age
BCmref[1,m] <- BCmth[1,1]
m <- m+2
}
And I am receiving the below error after a run of the entire loop:
Error in BCstore[1:size(BCmth[, 4], 1), m] <- BCmth[, 2] :
number of items to replace is not a multiple of replacement length
PLEASE NOTE: I am using the matlab package and the "size" function used here is the function relating to Matlab's usage of the word.
Thank you in advance for any help.