Simple example for creating a custom S3 class with methods

It can be really handy to create your own classes and methods in R. Most obviously it's very handy if you're creating a package for a particular procedure. Then you'd want a summary() method to quickly get some descriptive statistics, a plot() method to display results in a graphical manner, and so on. But also outside of writing packages might a custom class and a few methods come in handy. Most frequently in my experience it's in the form of a print() method.

Creating an S3 class and methods can be really simple, while still make life (or at least coding) that little bit less cumbersome.

Stratified partitioning – uniform and normal test

I claimed in a previous post that my method of selecting the number of strata when performing stratified partitioning on a uniformly distributed continuous variable, gave the optimal result, as measured by between-fold variance. All well and good, you might think, but there's one big problem. The variable i partitioned wasn't merely uniformly distributed, it was distributed entirely regularly and evenly.

Append element to function body

I don't use append() very often, but when I do I'm a little annoyed when I rediscover that I can't reference elements by name, but have to do it by index only. It's especially irksome as to add this feature all you'd have to do is include a couple of short and simple lines of code.

It's such a simple change that I figured I wouldn't even have to do it in an editor, I could do it all programmatically.