Automatic descriptive statistic tables

Here is some code I worked on a while back to make the process of generating descriptive tables quicker. This was driven by constantly making data frames for and calculating means or counts for either sex or genotype divisions, then having to completely restructure code if a new level was introduced for one factor.

Update – Nov 2013
https://github.com/nzcoops/r-code
The site I was hosting the code on closed, scripts are now available on my github.

Gallery with 3 examples of tables generated with one line of code, using html export option.

Calculating Age

Both ‘first’ and ‘second’ need to be date vectors. This is to achieve a calculation of age rounded DOWN in the same way that we say our age (as in we say 17, right up until the day we turn 18). round(x,0) will round up, floor(x) will also cause issues, if the two dates are the same day of the same month but on different years.

EDIT: This had an error and has been superseded by this post.