R365: Day 39- For loops


Busted my hand yesterday so I cant really type

For loops are useful to iterate a process for a given length of time

this example outlines how to set up a basic for loop

the cat() call (haha) might not be necessary, there might be ways around it, but i cant figure them out now


#based on code developed by Carol Hom
#a for loop to monitor the progress of a gut parasite
#pretend i had more than you initially, but i am fairly resiliant against the parasites
#set initial parameters for parasite populations
#set a vector to record the populations as the for-loop progresses
#set initial population. me is a vector so me[] tells you which point in the vector to set as the initial
#the for loop has to be of length me. One way to get around that is to set it to length(me) instead of 30
for (t in 2:length(me)){
 #set howthe pop will grow. you could also use me[1] instead of me.init
 #catenulate time, pop me, pop you, and end the line
 #dontforget to close out
#create a matrix called data by binding the two columns called me and you
#plot the log of the parasite loads in me and you
matplot(1:100,data,pch=20,25,xlab="time",ylab="log parasite load",type="b");

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s