# function

### Clarke and Ainsworth’s BIOENV and BVSTEP (and BIO-BIO etc…)

June 30, 2011 |

Nonmetric Multidimensional Scaling (NMDS) plot of vegetation sample dissimilarities with best correlating environmental variables (left) and species (right) plotted as vectors (datasets "varespec" and "varechem" from the package ...

### Image color palette replacement

June 9, 2011 |

Here is an example of a function I wrote to change the color palette used in an image. The above example comes from a black and white original, although color images can also be used. The function first converts the image to grayscale in order to have ...

### map.xyz(): interpolation of XYZ data and projection onto a map

May 30, 2011 |

I am still struggling to get a grasp of R's mapping capabilities. Part of my frustration lies in the fact that I often work on areas near the poles, which complicates interpolation across the 180 degree line. For smaller areas, interpolati...

### Array position to matrix coordinates conversion

May 30, 2011 |

#A function that is sometimes useful in determining the #coordinate(i.e. row and column number) of a matrix position#(and vice-versa). #Either a vector of positions ("pos") #OR a 2 column matrix of matrix coordinates, ("coord", i.e. cbind(row,col)), #A...

### R functions for Earth geographic coordinate calculations

May 29, 2011 |

Here are some functions that I regularly use for geographic data (e.g. binning, filtering, calculation of new positions etc.).#distance in kilometers between two long/lat positions (from "fossil" package)earth.dist

### Example 8.35: Grab true (not pseudo) random numbers; passing API URLs to functions or macros

April 19, 2011 |

Usually, we're content to use a pseudo-random number generator. But sometimes we may want numbers that are actually random-- an example might be for randomizing treatment status in a randomized controlled trial.The site Random.org provides truly rando...

### Programming with R – Checking Data Types

November 13, 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. Following on from ... [Read more...]

### Programming with R – Returning Information as a List

November 1, 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. We can ... [Read more...]

### Programming with R – Checking Function Arguments

October 24, 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. R has various ... [Read more...]

### Programming with R – Function Basics

October 20, 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 ... [Read more...]

### Probability of hypercubes…

November 28, 2009 |

…in R of course! There is a handy function to do those calculations. Normally (ahh!) you might resolve to a symbolic calculation package (Maple,Mathematica etc.)  but that is not the situation any more. The calculations are done with the mnormt package. Relevant functions exist in other packages as well (... [Read more...]

### Tips from the R-help list : shadow text in a plot and bumps charts

April 28, 2009 |

Stumbling across the R-help mailing-list I found, as often happens,  two threads in the spirit of this blog (of course, since they come from the list, the quality is higher): here you can find a function allowing  a shadow outline style for a...