Better summary function in R

The summary function in R returns:

For the univariate case I wrote what I consider to be a better summary function which returns:

The ideas behind it are:
1. I don’t really care about the quartiles, I can always create the box-plot or the histogram.
2. I think the standard deviation, Skewness and Kurtosis are interesting.
3. I want to know not only if I have NA’s but also where are they. It is somewhat less disturbing to have two consecutive NA’s at the end of series, than at random locations. e.g.:

4. I always want to know the length and at least one of “head” or “tail” to double check I load the series correctly as I intend and not different series by mistake.
5. Visualize: the function has a “plot” argument which, when set to “TRUE” returns a (2,1) figure with a standard scatter plot in the upper half and a histogram on the lower half.

Next is a multivariate extension, till then we loop. Let me know if bugs are spotted or you are familiar with (or made changes yourself to create) something better. Thanks.
1. This function uses “Kurtosis” and “Skewness” functions, both can be found in package “e1071” or package “moments” so you need at least one of those packages to avoid errors.
2. I use “suppressWarnings” since the function “sd” produces some meaningless warning which I want to ignore.
3. Alter the function for your own needs.

Leave a Reply

Your email address will not be published. Required fields are marked *