Useful functions for data frames in R

February 17th, 2012

This post will consider some useful functions for dealing with data frames during data processing and validation. Read the rest of this entry »

Getting rid of white space at the beginning and end of a string

July 28th, 2011

There are situations where we are working with character strings extracted from various sources and it can be annoying when there is white space at the beginning and/or end of the strings. This whitespace can cause problems when attemping to sort, subset or various other common operations. Read the rest of this entry »

Handling Errors Gracefully

May 27th, 2011

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. Read the rest of this entry »

R Matrix Operations

March 27th, 2011

R can be used to perform various matrix calculations. This include functions for creating matrices (matrix), addition (+), multiplication (%*%) and inversion (solve). Read the rest of this entry »

Programming with R – Processing Football League Data Part II

December 3rd, 2010

Following on from the previous post about creating a football result processing function for data from the football-data.co.uk website we will add code to the function to generate a league table based on the results to date. Read the rest of this entry »

Programming with R – Processing Football League Data Part I

November 23rd, 2010

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. Read the rest of this entry »

Programming with R – Checking Data Types

November 13th, 2010

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. Read the rest of this entry »

Programming with R – Returning Information as a List

November 2nd, 2010

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. Read the rest of this entry »

Programming with R – Checking Function Arguments

October 25th, 2010

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. Read the rest of this entry »

Programming with R – Function Basics

October 20th, 2010

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 might be interested in running the same initial analysis on the data. Read the rest of this entry »