Measuring the length of time to run a function

March 16th, 2010

When writing R code it is useful to be able to assess the amount of time that a particular function takes to run. We might be interested in measuring the increase in time required by our function as the size of the data increases. Read the rest of this entry »

Program Flow – Loops

September 4th, 2009

The R programming language has keywords defined to allow the user to defined loops in various ways – as a for, while or repeat statement. These statements can be used to ensure that a section of code is repeated multiple times until a defined condition has been satisfied. Read the rest of this entry »

Program Flow – Using Conditional Statements

June 21st, 2009

The R environment is based on providing access to the R programming language, which like other programming languages has a variety of constructions that can be used to control the flow of the analysis to make various decisions based on testing conditions. For each, in a function for numerical optimisation we might be interested in specifying a tolerance level to determine when the algorithm should stop or a maximum number of iterations. Read the rest of this entry »

Vector Calculations to avoid Explicit Loops

May 23rd, 2009

The S programming language has facilities for applying a function to all the individual elements of a vector, matrix or data frame which avoid the need to make explicit use of loops. In fact using loops in R is not recommended as this will slow down the calculations, but there will of course be some situations where it is unavoidable. Read the rest of this entry »