When analyzing a variable, one of the first things you want to do is to count how many non-missing (or non-NA) values the variable has. Unfortunately, there’s no default functions in R that perform this simply task. The length() function counts every element including the NAs. But it’s not hard to use it together with a if clause to handle NAs.

The default summary() function only returns the min, 1st quantile, median, mean, 3rd quantile and max of the input vector. However, you often also want to know its non-NA value counts, standard deviation, skewness and excess kurtosis. It’d be nice if there’s one function that returns all these summary statistics. So I wrote summary2(), which does exactly that. It leverages length2(), no_na_summary(), and the skewness() and kurtosis() functions in the e1071 package.

Use these functions and tell others how they’ve made your daily data analysis job easier.