S Programming

Handling Errors Gracefully

May 27, 2011 | Ralph

In R functions sometimes produces warnings or errors. In the case of errors execution of a function or a series of commands can get halted when an error occurs, which can in some cases be frustrating especially if we want to continue our calculations. There are various functions available in ... [Read more...]

R Matrix Operations

March 27, 2011 | Ralph

R can be used to perform various matrix calculations. This include functions for creating matrices (matrix), addition (+), multiplication (%*%) and inversion (solve). Fast Tube by Casper Other useful resources are provided on the Supplementary Material... [Read more...]

Programming with R – Processing Football League Data Part I

November 23, 2010 | Ralph

In this post we will make use of football results data from the football-data.co.uk website to demonstrate creating functions in R to automate a series of standard operations that would be required for results data from various leagues and divisions. The first step is to consider what control ... [Read more...]

Programming with R – Checking Data Types

November 13, 2010 | Ralph

There are a number of useful functions in R that test the variable type or convert between different variable types. These can be used to validate function input to ensure that sensible answers are returned from a function or to ensure that the function doesn’t fail. Following on from ... [Read more...]

Programming with R – Returning Information as a List

November 1, 2010 | Ralph

In previous posts (here and here) we created a simple function that returns a single numeric value. In some situations it may be more useful to return a more flexible data type, such as a list object, to provide more information about the calculations that have been performed. We can ... [Read more...]

Programming with R – Checking Function Arguments

October 24, 2010 | Ralph

In a previous post we considered writing a simple function to calculate the volume of a cylinder by specifying the height and radius of the cylinder. The function did not have any checking of the validity of the function arguments which we will consider in this post. R has various ... [Read more...]

Programming with R – Function Basics

October 20, 2010 | Ralph

One of the benefits of using R for statistical analysis is the programming language which allows users to define their own functions, which is particularly useful for analysis that needs to be repeated. For example, a monthly output from a database may be provided in a pre-determined format and we ... [Read more...]

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)