If you've performed a pre-post study, or any other kind of paired study, and some of the samples end up being nonsense, unusable, or missing, what do you do?
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.
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.
This is a suggestion for an approach to creating optimal strata of a continuous variable for further partitioning, followed by a visual justification for this assessment.
The partitioning itself is done with createFolds() from the caret package, but grouping, plotting and all the rest does not depend on any external library.
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.
A recent question on StackOverflow inspired me to develop a good method for finding the coordinates of intersection between two lines. As the method takes as input a discrete set of points and relies on interpolation (linear, cubic, or any other) to make a line, it's important to be aware of the assumptions being made.