Age-structured code: help getting started with loops

This help is relevant to Homework Set 3 (Dynamics of age-structured populations) Q2. To get started you can try the R code below. To see the effects of transient dynamics you will find it easier to look at about 10-20 time steps (not 50). You can do that by changing “barplot(m)” to “barplot(m[,1:10])” – where 10 is just an example (i.e. the first 10 time steps)
———–
# Choose one of the initial states:
n.0<-c(60,0,0,0,0,0)
# Create a 6(rows)x50(time steps) matrix to store results, and at first just fill it with zeros:
m<-matrix(rep(0,6*50),nrow=6)
# Put the first population data in first column
m[,1]<-n.0
# Now we create a loop to calculate the other 49 time steps (and store them in the next 49 columns)
for (i in 2:50){
  m[,i]<-LeslieSolve(m[,i-1])
}
# Make a barplot as before
barplot(m)