Error in BEEFPRODACT[ENDDAY[j], j] : subscript out of bounds

Hi I am using LiGAPS beef model to analyze my data. The model is long and coded in R. The following error is preventing the whole code from running. May you assist me, I keep getting Error in BEEFPRODACT[ENDDAY[j], j] : subscript out of bounds

j is your subscript
A number indicating which element from a set of elements is being pulled out. Out of bounds means trying to pull out an element that is not there.
Like if I tell you have a box with 7 apples, and you ask for the 8th apple, your request is out of bounds.

So how do i deal with that, in the code J is coming from here
for (j in 1:jmax){ # Loop for individual animals starts here (j = jth animal)
And the jmax code is the one below.
if(SCALE== 1) SEX <- SEX_ANIMAL else SEX <- c(1,SEX_CALVES)
jmax <- MAXCALFNR + 1 # Number of animals in the simulation at the animal level or the herd
# level
MAXCALFNR is 8 meaning eventully my jmax value is 9. So where do i edit now and how

So then the question becomes whether ENDDAY has 9 things and whether beefproduct has 9 in its 2nd dimension, and if all the values of ENDDAY from 1 to 9 are themselves present in the first dimension of beefproduct

here is the ENDDAY code with 9 things
ENDDAY = c(1,1,1,1,1,1,1,1,1)

Another related code hereunder

Day the animal is slaughtered (days)

# Is initially 9999, but is replaced by the correct number of days at slaughter
# Beef production at slaughter (kg per animal)
# Beef production (kg beef per head per year)
# Live weight production at slaughter (kg per animal)
if(ENDDAY[j] < 9999) LWPROD[j] <- LWPRODACT[ENDDAY[j],j] 
# Live weight production (kg live weight per head per year)
if(ENDDAY[j] < 9999) LWPRODYEAR[j] <- LWPRODACT[ENDDAY[j],j]/(TIME[ENDDAY[j],j]/365) 

The model is very long with many codes. Would you be available to assist me via an online short meeting where i can share my screen, please contact me via direct message.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.