-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
project.org] On Behalf Of John Kane
Sent: Monday, February 18, 2013 10:50 AM
To: Sam Fowler; r-help at r-project.org
Subject: Re: [R] help with population matrix
Currently your code does not seem to make any sense
===comments in line====
John Kane
Kingston ON Canada
-----Original Message-----
From: sf62 at st-andrews.ac.uk
Sent: Mon, 18 Feb 2013 16:09:49 +0000
To: r-help at r-project.org
Subject: [R] help with population matrix
Hi guys, I am a biologist and an R newbie, and I'm learning how to
a
simple population model.
So, I have a population matrix ("pop")of 30 age classes of female
are
non-breeders, 5:30 are breeders) which will be modelled for 100
I then populate this matrix with 3 young adult females.
What is this expected to do?
I then want to run this for 100 years, with stochasticity, to see how
this
population does over time.
for (y in 1:100) {
pop[1,t+1] <- rbinom(1,colSums(pop[5:30, t]), b/2)
(I haven't filled these in but you don't need them, they all have
different
survival probabilities to the sexually-mature adults.)
pop[5, t+1] <- rbinom(1, pop[4, t], s2)
pop[6, t+1] <- rbinom(1, pop[5, t], s2)
pop[30, t+1] <- rbinom(1, pop[29, t], s2)
So my question is: is there any way of populating this matrix without
having to explicitly write 30 lines of code? Because lines 5 - 30 are
going to be the same, and yet even after 5 hours (literally) of web
searching and R manual reading I can't find a way to index the rows,
which
seems to be what's needed here.
Any insight is welcome here, including a different way of modelling
population.
Many thanks, Sam.
This may be one of the cases where it really is better to have some
detailed explanation of what you want rather than how to code it.